kuuid
Version:
Time-sortable UUID - roughly time-sortable unique id generator
23 lines (18 loc) • 594 B
JavaScript
import test from 'node:test'
import assert from 'node:assert/strict'
import { ts } from './ts.js'
test('should return the current timestamp', function () {
const t1 = ts()
const t2 = Math.floor(new Date().getTime() / 1000)
const diff = Math.abs(t2 - t1)
const lessThanASecond = (diff < 1)
assert(lessThanASecond)
})
test('should return timestamp given string date', function () {
const t1 = ts('2018-01-01')
assert.strictEqual(t1, 1514764800)
})
test('should return timestamp given number of milliseconds', function () {
const t1 = ts(99000)
assert.strictEqual(t1, 99)
})