Date Time
Utilities for dates and times on Temporal: global DateTime, DateTimeRange and TimeSpan classes that parse localized input.
Installation
npm install @3mo/date-time
import { DateTime, DateTimeRange, TimeSpan } from '@3mo/date-time'
Usage
<span>${now.format({ dateStyle: 'full', timeStyle: 'short' })}</span>
<span>${now.formatAsDate()}</span>
<span>${now.format({ week: 'medium' })}</span>
Examples
- Arithmetic — Every operation returns a new
DateTime:add,subtractandwithtake Temporal durations and fields, the…Start,…Endand…Rangegetters snap to a day, week, month or year, andsincemeasures aTimeSpan. - Parsing —
toDateTime()reads what people type, in the language's own order: a full date, a day of this month (15), day and month (1503), an offset (+3,-2 weeks) or0for today. - Ranges — A
DateTimeRangehas two ends, either of which may be open, and formats them the way the language writes ranges.
API
Exports
| Name | Kind | Description |
|---|---|---|
DateTimeParser | class | |
DateTimeZeroParser | class | |
DateTimeOperationParser | class | |
DateTimeLocalParser | class | |
DateTimeShortcutParser | class | |
DateTimeNativeParser | class | |
DateTimeRangeParser | class | |
DateTimeRangeDelimiterParser | class | |
DateTime | class | A Date with Temporal's fields and arithmetic in the language's calendar and time zone, which also parses localized input. |
DateTimeRange | class | A range between two DateTimes, either of which may be open, formatted and parsed the way the language writes ranges. |
TimeSpan | class | A duration in milliseconds, formatted as relative time such as "in 3 days". |
Links
License
MIT © 3MO GmbH