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(); +});