From b3d6988d13e590bf2e55cded27c188013ed69a57 Mon Sep 17 00:00:00 2001 From: Huanyi Xie <74809554+xiehuanyi@users.noreply.github.com> Date: Thu, 8 Oct 2026 14:25:24 +0300 Subject: [PATCH] fix: derive short years from the full calendar year --- src/index.js | 2 +- test/short-years.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/short-years.js diff --git a/src/index.js b/src/index.js index 3ea001b..a213239 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ var RGX = /([^{]*?)\w(?=\})/g; var MAP = { YYYY: 'getFullYear', - YY: 'getYear', + YY: 'getFullYear', MM: function (d) { return d.getMonth() + 1; }, diff --git a/test/short-years.js b/test/short-years.js new file mode 100644 index 0000000..5d4f78d --- /dev/null +++ b/test/short-years.js @@ -0,0 +1,12 @@ +const test = require('tape'); +const fn = require('../dist/tinydate'); + +test('short years before 1900', t => { + const stamp = fn('{YY}'); + for (const year of [1, 50, 99, 1801, 1851, 1899, 1900, 2001]) { + const date = new Date(0); + date.setFullYear(year); + t.is(stamp(date), ('0' + (year % 100)).slice(-2), 'short year for ' + year); + } + t.end(); +});