Skip to content

Commit

Permalink
chore: Add locale
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Mar 7, 2019
1 parent 08be44a commit 37ab09f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/plugin/badMutable/index.js
Expand Up @@ -22,5 +22,12 @@ export default (o, c) => { // locale needed later
this.init()
return this
}

const oldLocale = proto.locale
proto.locale = function (preset, object) {
if (!preset) return this.$L
this.$L = oldLocale.bind(this)(preset, object).$L
return this
}
}

13 changes: 13 additions & 0 deletions test/plugin/badMutable.test.js
Expand Up @@ -2,6 +2,7 @@ import MockDate from 'mockdate'
import moment from 'moment'
import dayjs from '../../src'
import badMutable from '../../src/plugin/badMutable'
import '../../src/locale/zh-cn'

dayjs.extend(badMutable)

Expand Down Expand Up @@ -148,3 +149,15 @@ it('daysInMonth', () => {
expect(d.daysInMonth()).toBe(m.daysInMonth())
expect(d.format()).toBe(m.format())
})

it('Locale', () => {
const d = dayjs()
const m = moment()
const format = 'MMMM'
expect(d.locale()).toBe(m.locale())
expect(d.format(format)).toBe(m.format(format))
d.locale('zh-cn')
m.locale('zh-cn')
expect(d.locale()).toBe(m.locale())
expect(d.format(format)).toBe(m.format(format))
})

0 comments on commit 37ab09f

Please sign in to comment.