Skip to content

Commit

Permalink
fix: Update locale (zh-cn) meridiem (#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Dec 8, 2019
1 parent e31e544 commit 15d1b81
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-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,21 @@ const locale = {
y: '1 年',
yy: '%d 年'
},
meridiem: hour => (hour < 12 ? '上午' : '下午')
meridiem: (hour, minute) => {
const hm = (hour * 100) + minute
if (hm < 600) {
return '凌晨'
} else if (hm < 900) {
return '早上'
} else if (hm < 1130) {
return '上午'
} else if (hm < 1230) {
return '中午'
} else if (hm < 1800) {
return '下午'
}
return '晚上'
}
}

dayjs.locale(locale, null, true)
Expand Down
21 changes: 21 additions & 0 deletions test/locale/zh-cn.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import moment from 'moment'
import MockDate from 'mockdate'
import dayjs from '../../src'
import '../../src/locale/zh-cn'

beforeEach(() => {
MockDate.set(new Date())
})

afterEach(() => {
MockDate.reset()
})

it('Meridiem', () => {
const dayjsObj = dayjs().locale('zh-cn')
const momentObj = moment().locale('zh-cn')
for (let i = 0; i <= 24; i += 1) {
expect(dayjsObj.add(i, 'hour').format('A'))
.toEqual(momentObj.clone().add(i, 'hour').format('A'))
}
})

0 comments on commit 15d1b81

Please sign in to comment.