25 行
1.0 KiB
TypeScript
25 行
1.0 KiB
TypeScript
|
|
import assert from 'node:assert/strict'
|
||
|
|
import test from 'node:test'
|
||
|
|
|
||
|
|
import { expirationStatus, millisecondsUntil, toTimestamp } from '../src/date'
|
||
|
|
|
||
|
|
test('toTimestamp accepts seconds, milliseconds and API date strings', () => {
|
||
|
|
assert.equal(toTimestamp(1_700_000_000), 1_700_000_000_000)
|
||
|
|
assert.equal(toTimestamp(1_700_000_000_000), 1_700_000_000_000)
|
||
|
|
assert.equal(toTimestamp('2026-07-17 12:30:00'), new Date('2026-07-17T12:30:00').getTime())
|
||
|
|
assert.equal(toTimestamp('invalid'), null)
|
||
|
|
})
|
||
|
|
|
||
|
|
test('expirationStatus uses one canonical strict end-time decision', () => {
|
||
|
|
const now = 1_700_000_000_000
|
||
|
|
assert.equal(expirationStatus(null, now), 'missing')
|
||
|
|
assert.equal(expirationStatus(now + 1, now), 'valid')
|
||
|
|
assert.equal(expirationStatus(now, now), 'expired')
|
||
|
|
assert.equal(expirationStatus(now - 1, now), 'expired')
|
||
|
|
})
|
||
|
|
|
||
|
|
test('millisecondsUntil keeps positive and negative durations', () => {
|
||
|
|
assert.equal(millisecondsUntil(2_000, 1_000), 1_000_000)
|
||
|
|
assert.equal(millisecondsUntil(1_000_000_000_000, 1_000_000_000_500), -500)
|
||
|
|
})
|