# @ehmpathy/uni-time

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

Latest version **1.10.0** (published 2026-01-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ehmpathy/uni-time
pnpm add @ehmpathy/uni-time
yarn add @ehmpathy/uni-time
bun add @ehmpathy/uni-time
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.10.0 |
| Published | 2026-01-05 |
| First published | 2024-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 4 |
| Unpacked size | 81.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | ehmpathy |
| Maintainers | uladkasach |
| Keywords | time, date, datetime, UniDate, UniDateTime, UniDuration |

## Links

- npm: https://www.npmjs.com/package/@ehmpathy/uni-time
- Repository: https://github.com/ehmpathy/uni-time
- Issues: https://github.com/ehmpathy/uni-time/issues
- npm.io page: https://npm.io/package/@ehmpathy/uni-time

## Dependencies (4)

- [date-fns](https://npm.io/package/date-fns.md) 3.6.0
- [type-fns](https://npm.io/package/type-fns.md) 1.21.0
- [helpful-errors](https://npm.io/package/helpful-errors.md) 1.5.3
- [domain-glossaries](https://npm.io/package/domain-glossaries.md) 1.0.0

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.10.0 (latest) — 2026-01-05
- 1.9.6 — 2026-01-05
- 1.9.5 — 2026-01-05
- 1.9.4 — 2026-01-04
- 1.9.1 — 2025-09-20
- 1.9.0 — 2025-09-12
- 1.8.2 — 2025-07-14
- 1.8.1 — 2025-07-05
- 1.7.4 — 2024-11-21
- 1.7.3 — 2024-11-21
- 1.7.2 — 2024-11-21
- 1.7.1 — 2024-09-12
- 1.7.0 — 2024-09-12
- 1.6.1 — 2024-09-01
- 1.6.0 — 2024-09-01
- … 8 more at https://npm.io/package/@ehmpathy/uni-time/versions

## README

# uni-time

![test](https://github.com/ehmpathy/uni-time/workflows/test/badge.svg)
![publish](https://github.com/ehmpathy/uni-time/workflows/publish/badge.svg)

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

```sh
npm install uni-time
```

# use

## Time, Date, DateTime

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

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


### assure that a date or datetime is in the universal format

```ts
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

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


## Duration

### declare a duration intuitively
```ts
const duration: UniDuration = { minutes: 7 }
```

### serialize to milliseconds
```ts
const durationInMs = toMilliseconds({ minutes: 7 })
```

### sleep
```ts
await sleep({ minutes: 7 })
```

---
_Source: https://npm.io/package/@ehmpathy/uni-time · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
