UNPKG

date-vir

Version:

Easy and explicit dates and times.

46 lines (45 loc) 1.82 kB
import { dayOfMonthBounds, hourBounds, millisecondsBounds, minuteBounds, monthNumberBounds, secondBounds, } from '@date-vir/duration'; import { defineShape, enumShape, intersectShape, rangeShape } 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: rangeShape({ ...hourBounds, default: hourBounds.min }), /** Minute of the hour: 0-59 */ minute: rangeShape({ ...minuteBounds, default: minuteBounds.min }), /** Second of the minute: 0-59 */ second: rangeShape({ ...secondBounds, default: secondBounds.min }), /** Millisecond of the second: 0-999 */ millisecond: rangeShape({ ...millisecondsBounds, default: millisecondsBounds.min }), /** 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: rangeShape({ ...monthNumberBounds, default: monthNumberBounds.min }), /** A day of the month: 1-31 depending on the month */ day: rangeShape({ ...dayOfMonthBounds, default: dayOfMonthBounds.min }), /** The timezone that this date/time is meant for / originated from. */ timezone: enumShape(Timezone, utcTimezone), }); /** * The complete {@link FullDate} represented in a shape definition. * * @category Shape */ export const fullDateShape = defineShape(intersectShape(datePartShape, timePartShape));