Skip to content

Commit 1e9ba76

Browse files
authored
fix: Add locale (zh-tw) meridiem (#2149)
1 parent cbe91fd commit 1e9ba76

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/locale/zh-tw.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,24 @@ const locale = {
4242
MM: '%d 個月',
4343
y: '1 年',
4444
yy: '%d 年'
45+
},
46+
meridiem: (hour, minute) => {
47+
const hm = (hour * 100) + minute
48+
if (hm < 600) {
49+
return '凌晨'
50+
} else if (hm < 900) {
51+
return '早上'
52+
} else if (hm < 1100) {
53+
return '上午'
54+
} else if (hm < 1300) {
55+
return '中午'
56+
} else if (hm < 1800) {
57+
return '下午'
58+
}
59+
return '晚上'
4560
}
4661
}
4762

4863
dayjs.locale(locale, null, true)
4964

5065
export default locale
51-

test/locale/zh-tw.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import dayjs from '../../src'
2+
import advancedFormat from '../../src/plugin/advancedFormat'
3+
import weekOfYear from '../../src/plugin/weekOfYear'
4+
import '../../src/locale/zh'
5+
import '../../src/locale/zh-tw'
6+
7+
dayjs.extend(advancedFormat).extend(weekOfYear)
8+
9+
const zh = dayjs().locale('zh')
10+
const zhTW = dayjs().locale('zh-tw')
11+
12+
test('ordinal', () => {
13+
expect(zh.format('wo')).toEqual(`${zh.format('w')}周`)
14+
expect(zhTW.format('wo')).toEqual(`${zhTW.format('w')}週`)
15+
})
16+
17+
test('Meridiem', () => {
18+
for (let i = 0; i <= 24; i += 1) {
19+
expect(zh.add(i, 'hour').format('A')).toBe(zhTW.add(i, 'hour').format('A'))
20+
}
21+
})

0 commit comments

Comments
 (0)