From 1668c0dd6bce991a1457b53a653a39446d5b2916 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Fri, 2 Oct 2026 16:02:11 +0200 Subject: [PATCH] feat: expose the tzdb version of the bundled zonefile --- scripts/tz/update.js | 2 +- src/index.js | 2 ++ test/tzdb.test.js | 9 +++++++++ types/constructors.d.ts | 3 +++ zonefile/_build.js | 1 + zonefile/iana.js | 1 + zonefile/pack.js | 7 +++++-- 7 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/tzdb.test.js diff --git a/scripts/tz/update.js b/scripts/tz/update.js index 8d89968..f9a41f4 100644 --- a/scripts/tz/update.js +++ b/scripts/tz/update.js @@ -187,7 +187,7 @@ export const main = (args = process.argv.slice(2)) => { tzdata: version, unsupported: unsupported.map((o) => o.name) }) - const text = `// Generated by scripts/tz/update.js: ${source}\nexport default ${JSON.stringify(result, null, 2)}\n` + const text = `// Generated by scripts/tz/update.js: ${source}\nexport const tzdbVersion = ${JSON.stringify(version)}\nexport default ${JSON.stringify(result, null, 2)}\n` // Rename within the destination directory so readers never see a partial file. // Only remove a temporary file created by this run (exclusive creation may fail). const temporary = join(dirname(options.output), `.zonefile-${process.pid}.tmp`) diff --git a/src/index.js b/src/index.js index 504609c..8d8990b 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ import Spacetime from './spacetime.js' import whereIts from './whereIts.js' import version from './_version.js' +import { tzdbVersion } from '../zonefile/_build.js' const main = (input, tz, options) => new Spacetime(input, tz, options) @@ -62,6 +63,7 @@ main.min = function (tz, options) { //find tz by time main.whereIts = whereIts main.version = version +main.tzdbVersion = tzdbVersion //aliases: main.plugin = main.extend diff --git a/test/tzdb.test.js b/test/tzdb.test.js new file mode 100644 index 0000000..a2ba321 --- /dev/null +++ b/test/tzdb.test.js @@ -0,0 +1,9 @@ +import test from 'tape' +import spacetime from './lib/index.js' +import { tzdbVersion } from '../zonefile/iana.js' + +test('tzdb version', (t) => { + t.ok(/^\d{4}[a-z]+$/.test(spacetime.tzdbVersion), `looks like '2026c'`) + t.equal(spacetime.tzdbVersion, tzdbVersion, 'same as zonefile/iana.js') + t.end() +}) diff --git a/types/constructors.d.ts b/types/constructors.d.ts index 7baf2f2..3326bcf 100644 --- a/types/constructors.d.ts +++ b/types/constructors.d.ts @@ -86,6 +86,9 @@ export interface SpacetimeStatic extends SpacetimeConstructor { /** list timezones by their time */ whereIts: (a: string, b?: string) => string[] + /** IANA tzdb release of the bundled timezone data, like '2026c' */ + tzdbVersion: string + /** set as earliest-possible date */ min: (timezone?: string, options?: SpacetimeConstructorOptions) => Spacetime diff --git a/zonefile/_build.js b/zonefile/_build.js index 86d49e2..ff5e5a9 100644 --- a/zonefile/_build.js +++ b/zonefile/_build.js @@ -1,3 +1,4 @@ +export const tzdbVersion = "2026c" export default { "9|s": "2/dili,2/jayapura", "9|n": "2/chita,2/khandyga,2/pyongyang,2/seoul,2/tokyo,2/yakutsk,11/palau,japan,rok", diff --git a/zonefile/iana.js b/zonefile/iana.js index 5b186c8..8eac5bc 100644 --- a/zonefile/iana.js +++ b/zonefile/iana.js @@ -1,3 +1,4 @@ +export const tzdbVersion = '2026c' export default { 'africa/abidjan': { offset: 0, diff --git a/zonefile/pack.js b/zonefile/pack.js index 61f8f72..6717265 100644 --- a/zonefile/pack.js +++ b/zonefile/pack.js @@ -1,6 +1,6 @@ //turn our timezone data into a small-as-possible string import { writeFileSync } from 'node:fs' -import iana from './iana.js' +import iana, { tzdbVersion } from './iana.js' import aliases from './aliases.js' import prefixes from './_prefixes.js' const all = {} @@ -44,4 +44,7 @@ keys.forEach((k) => { }) // console.log(result) -writeFileSync('./zonefile/_build.js', 'export default ' + JSON.stringify(result, null, 2)) +writeFileSync( + './zonefile/_build.js', + `export const tzdbVersion = ${JSON.stringify(tzdbVersion)}\nexport default ${JSON.stringify(result, null, 2)}` +)