ortus 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (C) 2026 by planetrenox
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted.
5
+
6
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
7
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
8
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
9
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
10
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
11
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
12
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # ortus
2
+
3
+ **PRT (Planet Renox Time)**: milliseconds since `1998-03-14T03:00:00.000Z`.
4
+
5
+ ```sh
6
+ npm i ortus
7
+ ```
8
+
9
+ ```js
10
+ import { PRT } from 'ortus'
11
+
12
+ PRT.now() // PRT ms, the official unit
13
+ PRT.now('d') // days
14
+ PRT.fromDate(new Date('2010-06-01'), 'd') // 4461
15
+ PRT.toDate(1e9, 's') // 2029-11-20T04:46:40.000Z
16
+ PRT.fromUnixMs(Date.now()) // same as PRT.now()
17
+ PRT.toUnixMs(0) // 889844400000
18
+ ```
19
+
20
+ ## API
21
+
22
+ | | |
23
+ |---|---|
24
+ | `PRT.now(unit = 'ms')` | Current PRT |
25
+ | `PRT.fromDate(date, unit = 'ms')` | `Date` → PRT |
26
+ | `PRT.toDate(n, unit = 'ms')` | PRT → `Date` |
27
+ | `PRT.fromUnixMs(ms, unit = 'ms')` | Unix ms → PRT |
28
+ | `PRT.toUnixMs(n, unit = 'ms')` | PRT → Unix ms |
29
+
30
+ Units: `ms` (official), `s`, `m`, `h`, `d`, `w`.
31
+
32
+ ## Rules
33
+
34
+ - **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.
35
+ - **Before the epoch is negative.**
36
+ - **Strict input.** `fromDate` takes only valid `Date`s. `fromUnixMs`, `toDate`, and `toUnixMs` take only integers. Anything else throws.
37
+ - **No overflow.** Every value is exact across the full JS `Date` range (±275,000 years). Anything outside it throws.
38
+ - **Leap seconds are ignored**, the same as JS `Date`.
39
+ - **No dependencies.**
40
+
41
+ ## License
42
+
43
+ 0BSD. Use it however you want, no attribution needed.
package/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /** PRT units: milliseconds (official), seconds, minutes, hours, days, weeks */
2
+ export type Unit = 'ms' | 's' | 'm' | 'h' | 'd' | 'w'
3
+
4
+ export declare const PRT: Readonly<{
5
+ /** Current PRT, rounded down. Defaults to ms. */
6
+ now(unit?: Unit): number
7
+ /** PRT at the given Date, rounded down. Defaults to ms. */
8
+ fromDate(date: Date, unit?: Unit): number
9
+ /** Date at the given integer PRT value. Defaults to ms. */
10
+ toDate(value: number, unit?: Unit): Date
11
+ /** PRT at the given integer Unix ms, rounded down. Defaults to ms. */
12
+ fromUnixMs(unixMs: number, unit?: Unit): number
13
+ /** Unix ms at the given integer PRT value. Defaults to ms. */
14
+ toUnixMs(value: number, unit?: Unit): number
15
+ }>
16
+
17
+ export default PRT
package/index.js ADDED
@@ -0,0 +1,37 @@
1
+ // PRT — Planet Renox Time: ms since 1998-03-14T03:00:00.000Z
2
+ const E = 889844400000
3
+ const MAX = 8.64e15 // JS Date range, ±275k years
4
+ const U = { __proto__: null, ms: 1, s: 1e3, m: 6e4, h: 36e5, d: 864e5, w: 6048e5 }
5
+ const T = Date.prototype.getTime
6
+
7
+ const unit = u => {
8
+ if (typeof u != 'string' || !U[u]) throw new RangeError(`PRT: unknown unit ${String(u)}, use ms|s|m|h|d|w`)
9
+ return U[u]
10
+ }
11
+
12
+ // Math.floor rounds toward -Infinity, exact since every in-range ms diff is an integer below 2^53
13
+ const fromUnixMs = (t, u = 'ms') => {
14
+ if (!Number.isInteger(t)) throw new TypeError('PRT.fromUnixMs: expected an integer')
15
+ if (Math.abs(t) > MAX) throw new RangeError('PRT.fromUnixMs: out of Date range')
16
+ return Math.floor((t - E) / unit(u))
17
+ }
18
+
19
+ const fromDate = (date, u = 'ms') => {
20
+ let t
21
+ try { t = T.call(date) } catch {} // brand check: real Dates only, works across realms
22
+ if (!Number.isFinite(t)) throw new TypeError('PRT.fromDate: expected a valid Date')
23
+ return fromUnixMs(t, u)
24
+ }
25
+
26
+ const toUnixMs = (n, u = 'ms') => {
27
+ if (!Number.isSafeInteger(n)) throw new TypeError('PRT: expected an integer PRT value')
28
+ const t = n * unit(u) + E
29
+ if (!(Math.abs(t) <= MAX)) throw new RangeError('PRT: out of Date range')
30
+ return t
31
+ }
32
+
33
+ const now = (u = 'ms') => fromUnixMs(Date.now(), u)
34
+ const toDate = (n, u = 'ms') => new Date(toUnixMs(n, u))
35
+
36
+ export const PRT = Object.freeze({ now, fromDate, toDate, fromUnixMs, toUnixMs })
37
+ export default PRT
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "ortus",
3
+ "version": "0.1.1",
4
+ "description": "PRT (Planet Renox Time): milliseconds since 1998-03-14T03:00:00Z",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "default": "./index.js"
10
+ }
11
+ },
12
+ "types": "./index.d.ts",
13
+ "files": [
14
+ "index.js",
15
+ "index.d.ts"
16
+ ],
17
+ "sideEffects": false,
18
+ "scripts": {
19
+ "test": "node --test"
20
+ },
21
+ "keywords": [
22
+ "prt",
23
+ "planet renox time",
24
+ "time",
25
+ "timestamp",
26
+ "epoch"
27
+ ],
28
+ "license": "0BSD",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/planetrenox/ortus.git"
32
+ }
33
+ }