Skip to content

Commit

Permalink
fix: Add locale (zh-tw) meridiem (iamkun#2149)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin82222 authored and ohsory1324 committed Dec 20, 2023
1 parent 50cd7f6 commit 823e630
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/locale/zh-tw.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,24 @@ const locale = {
MM: '%d 個月',
y: '1 年',
yy: '%d 年'
},
meridiem: (hour, minute) => {
const hm = (hour * 100) + minute
if (hm < 600) {
return '凌晨'
} else if (hm < 900) {
return '早上'
} else if (hm < 1100) {
return '上午'
} else if (hm < 1300) {
return '中午'
} else if (hm < 1800) {
return '下午'
}
return '晚上'
}
}

dayjs.locale(locale, null, true)

export default locale

21 changes: 21 additions & 0 deletions test/locale/zh-tw.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import dayjs from '../../src'
import advancedFormat from '../../src/plugin/advancedFormat'
import weekOfYear from '../../src/plugin/weekOfYear'
import '../../src/locale/zh'
import '../../src/locale/zh-tw'

dayjs.extend(advancedFormat).extend(weekOfYear)

const zh = dayjs().locale('zh')
const zhTW = dayjs().locale('zh-tw')

test('ordinal', () => {
expect(zh.format('wo')).toEqual(`${zh.format('w')}周`)
expect(zhTW.format('wo')).toEqual(`${zhTW.format('w')}週`)
})

test('Meridiem', () => {
for (let i = 0; i <= 24; i += 1) {
expect(zh.add(i, 'hour').format('A')).toBe(zhTW.add(i, 'hour').format('A'))
}
})

0 comments on commit 823e630

Please sign in to comment.