Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/locale/en-ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ const locale = {
weekdaysShort: 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
monthsShort: 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
weekdaysMin: 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
ordinal: n => n,
ordinal: (n) => {
const s = ['th', 'st', 'nd', 'rd']
const v = n % 100
return `[${n}${(s[(v - 20) % 10] || s[v] || s[0])}]`
},
formats: {
LT: 'h:mm A',
LTS: 'h:mm:ss A',
Expand Down
6 changes: 5 additions & 1 deletion src/locale/en-ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const locale = {
weekdaysShort: 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
monthsShort: 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
weekdaysMin: 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
ordinal: n => n,
ordinal: (n) => {
const s = ['th', 'st', 'nd', 'rd']
const v = n % 100
return `[${n}${(s[(v - 20) % 10] || s[v] || s[0])}]`
},
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
Expand Down
6 changes: 5 additions & 1 deletion src/locale/en-il.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ const locale = {
weekdaysShort: 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
monthsShort: 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
weekdaysMin: 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
ordinal: n => n,
ordinal: (n) => {
const s = ['th', 'st', 'nd', 'rd']
const v = n % 100
return `[${n}${(s[(v - 20) % 10] || s[v] || s[0])}]`
},
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
Expand Down
6 changes: 5 additions & 1 deletion src/locale/en-sg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const locale = {
weekdaysShort: 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
monthsShort: 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
weekdaysMin: 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
ordinal: n => n,
ordinal: (n) => {
const s = ['th', 'st', 'nd', 'rd']
const v = n % 100
return `[${n}${(s[(v - 20) % 10] || s[v] || s[0])}]`
},
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
Expand Down
20 changes: 20 additions & 0 deletions test/locale/en.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import moment from 'moment'
import dayjs from '../../src'
import '../../src/locale/en'
import '../../src/locale/en-gb'
import '../../src/locale/en-in'
import '../../src/locale/en-tt'
import '../../src/locale/en-ca'
import '../../src/locale/en-ie'
import '../../src/locale/en-il'
import '../../src/locale/en-sg'
import localizedFormat from '../../src/plugin/localizedFormat'
import advancedFormat from '../../src/plugin/advancedFormat'

dayjs.extend(localizedFormat)
dayjs.extend(advancedFormat)

const locales = [
{ locale: 'en', expectedDate: '12/25/2019' },
Expand All @@ -22,3 +29,16 @@ describe('English date formats', () => {
})
})
})

describe('English ordinal (Do) parity with moment', () => {
const ordinalLocales = ['en-ca', 'en-ie', 'en-il', 'en-sg']
ordinalLocales.forEach((locale) => {
it(`should format the ordinal day of month like moment - ${locale}`, () => {
for (let d = 1; d <= 31; d += 1) {
const date = `2021-01-${String(d).padStart(2, '0')}`
expect(dayjs(date).locale(locale).format('Do'))
.toEqual(moment(date).locale(locale).format('Do'))
}
})
})
})