Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ehmpathy/uni-time

ehmpathy342MIT1.7.4TypeScript support: included

a glossary of universally intuitive time, date, and duration domain literals

time, date, datetime, UniDate, UniDateTime, UniDuration

readme

uni-time

test publish

A glossary of intuitive, universally unambiguous time, date, and duration domain literals.

purpose

declare a universally unambiguous serialization format for dates, times, and datetime

  • UniDate = yyyy-MM-dd
  • UniTime = hh:mm:ss.sss
  • UniDateTime = yyyy-MM-ddThh:mm:ss.sssZ

declare a universally intuitive interface for durations

  • UniDuration

usecases

  • clarify the format a date string should be in (const since: UniDate = '2013-12-15)
  • cast date to universal format (const birthday: UniDate = toUniDate(new Date()))
  • narrow type of strings with runtime validation (if (!isUniDate(since)) throw new Error('wrong format'))

install

npm install uni-time

use

Time, Date, DateTime

declare that a date or datetime must be in the universal format

const noon: UniTime;
const birthday: UniDate;
const occurredAt: UniDateTime;

assure that a date or datetime is in the universal format

const noon: UniTime = isUniTime.assure('12:00:00.000')
const birthday: UniDate = isUniDate.assure('2013-12-15')
const occurredAt: UniDateTime = isUniDateTime.assure('2013-12-15T07:21:13.555Z')

cast a date or datetime into the universal format

const birthday: UniDate = asUniDate(new Date())
const occurredAt: UniDateTime = asUniDateTime(new Date())

Duration

declare a duration intuitively

const duration: UniDuration = { minutes: 7 }

serialize to milliseconds

const durationInMs = toMilliseconds({ minutes: 7 })

sleep

await sleep({ minutes: 7 })

changelog

Changelog

1.7.4 (2024-11-21)

Bug Fixes

  • duration: add type overrides to distinguish grain in manipulators (40499e1)

1.7.3 (2024-11-21)

Bug Fixes

  • pkg: ensure isUniMonth utils are exported (f9b12bf)

1.7.2 (2024-11-21)

Bug Fixes

  • checks: add checks for UniMonth (6f061bc)

1.7.1 (2024-09-12)

Bug Fixes

  • types: ensure UniDateTimes are not assignable within UniDateRange (95a2376)

1.7.0 (2024-09-12)

Features

  • duration: expose get duration procedure (87b9d7b)

1.6.1 (2024-09-01)

Bug Fixes

  • practs: bump practs to latest best (ddbcff3)

1.6.0 (2024-09-01)

Features

  • observe: expose duration stopwatch (c70c2ab)

1.5.0 (2024-08-18)

Features

  • wrappers: expose waitFor wrapper (920410c)

1.4.2 (2024-07-21)

Bug Fixes

  • duration: support weeks as final duration grain (f99d8ce)

1.4.1 (2024-07-21)

Bug Fixes

  • duration: handle zero unit durations correctly (49805d4)

1.4.0 (2024-05-26)

Features

  • manip: addDuration and subDuration (0c198f5)

1.3.0 (2024-05-26)

Features

  • cast: toMillisecondsSinceEpoch (c91cd01)

1.2.0 (2024-05-25)

Features

  • checks: expose isUniDate and isUniDateTime checks with assure (f6680b6)

1.1.0 (2024-05-25)

Features

  • type: expose UniDateTimeRange (527dd1e)

1.0.1 (2024-05-25)

Bug Fixes

1.0.0 (2024-05-25)

Features

  • domain: expose UniDate, UniDateTime, UniDuration, checks, and sleep (68807d3)
  • init: initialize repo based on latest best practices (9bee9bc)