date-vir
Version:
Easy and explicit dates and times.
46 lines (45 loc) • 1.72 kB
JavaScript
import { dayOfMonthBounds, hourBounds, millisecondsBounds, minuteBounds, monthNumberBounds, secondBounds, } from '@date-vir/duration';
import { and, defineShape, enumShape, numericRange } from 'object-shape-tester';
import { Timezone, utcTimezone } from '../timezone/timezones.js';
/**
* Time part of {@link FullDate} represented in a shape definition.
*
* @category Shape
*/
export const timePartShape = defineShape({
/** Hour of the day in 24 time: 0-23 */
hour: numericRange(hourBounds.min, hourBounds.max),
/** Minute of the hour: 0-59 */
minute: numericRange(minuteBounds.min, minuteBounds.max),
/** Second of the minute: 0-59 */
second: numericRange(secondBounds.min, secondBounds.max),
/** Millisecond of the second: 0-999 */
millisecond: numericRange(millisecondsBounds.min, millisecondsBounds.max),
/** The timezone that this date/time is meant for / originated from. */
timezone: enumShape(Timezone, utcTimezone),
});
/**
* Date part of {@link FullDate} represented in a shape definition.
*
* @category Shape
*/
export const datePartShape = defineShape({
/**
* The full, four digit year.
*
* @example 2023;
*/
year: 2023,
/** A month of the year: 1-12 */
month: numericRange(monthNumberBounds.min, monthNumberBounds.max),
/** A day of the month: 1-31 depending on the month */
day: numericRange(dayOfMonthBounds.min, dayOfMonthBounds.max),
/** The timezone that this date/time is meant for / originated from. */
timezone: utcTimezone,
});
/**
* The complete {@link FullDate} represented in a shape definition.
*
* @category Shape
*/
export const fullDateShape = defineShape(and(datePartShape, timePartShape));