mirror of
https://github.com/planetrenox/ortus.git
synced 2026-10-29 04:34:53 +00:00
Zero-dependency ESM package with types. now, fromDate, toDate, fromUnixMs, toUnixMs; units ms|s|m|h|d|w, floored toward -Infinity, exact across the full JS Date range. 0BSD. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1.4 KiB
1.4 KiB
ortus
PRT (Planet Renox Time): milliseconds since 1998-03-14T03:00:00.000Z.
npm i ortus
import { PRT } from 'ortus'
PRT.now() // PRT ms, the official unit
PRT.now('d') // days
PRT.fromDate(new Date('2010-06-01'), 'd') // 4461
PRT.toDate(1e9, 's') // 2029-11-20T04:46:40.000Z
PRT.fromUnixMs(Date.now()) // same as PRT.now()
PRT.toUnixMs(0) // 889844400000
API
PRT.now(unit = 'ms') |
Current PRT |
PRT.fromDate(date, unit = 'ms') |
Date → PRT |
PRT.toDate(n, unit = 'ms') |
PRT → Date |
PRT.fromUnixMs(ms, unit = 'ms') |
Unix ms → PRT |
PRT.toUnixMs(n, unit = 'ms') |
PRT → Unix ms |
Units: ms (official), s, m, h, d, w.
Rules
- Always an integer, rounded down toward −∞.
1.5s → 1,-1.5s → -2, so every unit is the same length on both sides of the epoch. - Before the epoch is negative.
- Strict input.
fromDatetakes only validDates.fromUnixMs,toDate, andtoUnixMstake only integers. Anything else throws. - No overflow. Every value is exact across the full JS
Daterange (±275,000 years). Anything outside it throws. - Leap seconds are ignored, the same as JS
Date. - No dependencies.
License
0BSD. Use it however you want, no attribution needed.