Skip to content

Commit

Permalink
fix: Add locale (zh-tw) meridiem (#2149)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin82222 committed Dec 5, 2022
1 parent cbe91fd commit 1e9ba76
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
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
@@ -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 1e9ba76

Please sign in to comment.