@financial-times/ft-date-format
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -26,2 +26,3 @@ const months = '["' + 'January,February,March,April,May,June,July,August,September,October,November,December'.split(',').join('","') + '"]'; | ||
dd: 'pad2(date.getDate())', // 04 | ||
do: 'ordinal(date.getDate())', // 4th | ||
m: 'date.getMinutes()', // 5 | ||
@@ -50,2 +51,7 @@ mm: 'pad2(date.getMinutes())', // 05 | ||
funcString += 'function pad2 (number) {return ("0" + number).slice(-2)}'; | ||
funcString += `function ordinal(number) { | ||
const suffixes = ["th", "st", "nd", "rd"]; | ||
const v = number % 100; | ||
return number + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]); | ||
}`; | ||
funcString += 'return "' + tpl.replace(/\\?[a-z]+/ig, function (match) { | ||
@@ -52,0 +58,0 @@ if (match.charAt(0) === '\\') { |
@@ -92,2 +92,12 @@ /* eslint-env mocha */ | ||
it('returns ordinals formatted correctly', () => { | ||
const days = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th', | ||
'11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th', '20th', | ||
'21st', '22nd', '23rd', '24th', '25th', '26th', '27th', '28th', '29th', '30th', '31st']; | ||
for (let i = 1; i <= days.length; i++) { | ||
proclaim.strictEqual(ftDateFormat.format(new Date(2000, 0, i), 'do'), days[i - 1]); | ||
} | ||
}); | ||
it('returns an unpadded 12hour clock value for `h` format', () => { | ||
@@ -94,0 +104,0 @@ proclaim.strictEqual(ftDateFormat.format(someTimes["midnight"], 'h'), '12'); |
{ | ||
"name": "@financial-times/ft-date-format", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Utility for formatting and updating dates for Financial-Times customer-facing products", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36888
783