@everwhen/temporal
Version:
_description_
24 lines (23 loc) • 921 B
TypeScript
import type { DateTimeUnit } from '../type-utils.ts';
/**
* Generates temporal units from largest to smallest within a specified range.
*
* @param options.largest - The largest unit to start from (default: 'year')
* @param options.smallest - The smallest unit to end at (default: 'nanosecond')
* @throws Error if largest unit is smaller than smallest unit in the temporal hierarchy
*
* @example
* // Iterate over all date units
* for (const unit of temporalUnits({ largest: 'year', smallest: 'day' })) {
* console.log(unit) // 'year', 'month', 'week', 'day'
* }
*
* @example
* // Get time units as an array
* const timeUnits = Array.from(temporalUnits({ largest: 'hour', smallest: 'millisecond' }))
* // ['hour', 'minute', 'second', 'millisecond']
*/
export declare function temporalUnits({ largest, smallest, }?: {
largest?: DateTimeUnit;
smallest?: DateTimeUnit;
}): Generator<DateTimeUnit>;