From c39fb96e2a9102c14b004c14a6c073af9d266f2f Mon Sep 17 00:00:00 2001 From: ElliotAshby <47282526+ElliotAshby@users.noreply.github.com> Date: Fri, 3 Apr 2020 12:00:42 +0100 Subject: [PATCH] fix: Add en-in, en-tt locales (#855) --- src/locale/en-in.js | 46 ++++++++++++++++++++++++++++++++++++++++++ src/locale/en-tt.js | 46 ++++++++++++++++++++++++++++++++++++++++++ test/locale/en.test.js | 24 ++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/locale/en-in.js create mode 100644 src/locale/en-tt.js create mode 100644 test/locale/en.test.js diff --git a/src/locale/en-in.js b/src/locale/en-in.js new file mode 100644 index 000000000..9913857a9 --- /dev/null +++ b/src/locale/en-in.js @@ -0,0 +1,46 @@ +// English (India) [en-in] +import dayjs from 'dayjs' + +const locale = { + name: 'en-in', + weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'), + weekdaysShort: 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'), + weekdaysMin: 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'), + months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'), + monthsShort: 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'), + weekStart: 1, + yearStart: 4, + relativeTime: { + future: 'in %s', + past: '%s ago', + s: 'a few seconds', + m: 'a minute', + mm: '%d minutes', + h: 'an hour', + hh: '%d hours', + d: 'a day', + dd: '%d days', + M: 'a month', + MM: '%d months', + y: 'a year', + yy: '%d years' + }, + formats: { + LT: 'HH:mm', + LTS: 'HH:mm:ss', + L: 'DD/MM/YYYY', + LL: 'D MMMM YYYY', + LLL: 'D MMMM YYYY HH:mm', + LLLL: 'dddd, D MMMM YYYY HH:mm' + }, + ordinal: (n) => { + const s = ['th', 'st', 'nd', 'rd'] + const v = n % 100 + return `[${n}${(s[(v - 20) % 10] || s[v] || s[0])}]` + } +} + +dayjs.locale(locale, null, true) + +export default locale + diff --git a/src/locale/en-tt.js b/src/locale/en-tt.js new file mode 100644 index 000000000..99212232e --- /dev/null +++ b/src/locale/en-tt.js @@ -0,0 +1,46 @@ +// English (Trinidad & Tobago) [en-tt] +import dayjs from 'dayjs' + +const locale = { + name: 'en-tt', + weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'), + weekdaysShort: 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'), + weekdaysMin: 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'), + months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'), + monthsShort: 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'), + weekStart: 1, + yearStart: 4, + relativeTime: { + future: 'in %s', + past: '%s ago', + s: 'a few seconds', + m: 'a minute', + mm: '%d minutes', + h: 'an hour', + hh: '%d hours', + d: 'a day', + dd: '%d days', + M: 'a month', + MM: '%d months', + y: 'a year', + yy: '%d years' + }, + formats: { + LT: 'HH:mm', + LTS: 'HH:mm:ss', + L: 'DD/MM/YYYY', + LL: 'D MMMM YYYY', + LLL: 'D MMMM YYYY HH:mm', + LLLL: 'dddd, D MMMM YYYY HH:mm' + }, + ordinal: (n) => { + const s = ['th', 'st', 'nd', 'rd'] + const v = n % 100 + return `[${n}${(s[(v - 20) % 10] || s[v] || s[0])}]` + } +} + +dayjs.locale(locale, null, true) + +export default locale + diff --git a/test/locale/en.test.js b/test/locale/en.test.js new file mode 100644 index 000000000..c7b3de1b3 --- /dev/null +++ b/test/locale/en.test.js @@ -0,0 +1,24 @@ +import dayjs from '../../src' +import '../../src/locale/en' +import '../../src/locale/en-gb' +import '../../src/locale/en-in' +import '../../src/locale/en-tt' +import localizedFormat from '../../src/plugin/localizedFormat' + +dayjs.extend(localizedFormat) + +const locales = [ + { locale: 'en', expectedDate: '12/25/2019' }, + { locale: 'en-gb', expectedDate: '25/12/2019' }, + { locale: 'en-in', expectedDate: '25/12/2019' }, + { locale: 'en-tt', expectedDate: '25/12/2019' } +] + +describe('English date formats', () => { + locales.forEach((locale) => { + it(`should correctly format date with locale - ${locale.locale}`, () => { + const dayjsWithLocale = dayjs('2019-12-25').locale(locale.locale) + expect(dayjsWithLocale.format('L')).toEqual(locale.expectedDate) + }) + }) +})