Skip to content

Commit

Permalink
fix: Allow set start day of week in locale && Allow set week in weekO…
Browse files Browse the repository at this point in the history
…fYear plugin
  • Loading branch information
iamkun committed Feb 5, 2019
1 parent 9ad732c commit 1295591
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/index.js
Expand Up @@ -172,8 +172,7 @@ class Dayjs {
return isStartOf ? instanceFactory(1, this.$M) :
instanceFactory(0, this.$M + 1)
case C.W: {
const l = this.$locale()
const weekStart = l && l.weekStart === 1 ? 1 : 0
const weekStart = this.$locale().weekStart || 0
return isStartOf ? instanceFactory(this.$D - (this.$W - weekStart), this.$M) :
instanceFactory(this.$D + (6 - (this.$W - weekStart)), this.$M)
}
Expand Down
1 change: 1 addition & 0 deletions src/locale/zh-cn.js
Expand Up @@ -8,6 +8,7 @@ const locale = {
months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_'),
monthsShort: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
ordinal: n => `${n}日`,
weekStart: 1,
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
Expand Down
5 changes: 5 additions & 0 deletions test/manipulate.test.js
@@ -1,6 +1,7 @@
import moment from 'moment'
import MockDate from 'mockdate'
import dayjs from '../src'
import '../src/locale/zh-cn'

beforeEach(() => {
MockDate.set(new Date())
Expand Down Expand Up @@ -28,6 +29,10 @@ describe('StartOf EndOf', () => {
expect(dayjs().startOf('otherString').valueOf()).toBe(moment().startOf('otherString').valueOf())
expect(dayjs().endOf('otherString').valueOf()).toBe(moment().endOf('otherString').valueOf())
})

it('StartOf week with locale', () => {
expect(dayjs().locale('zh-cn').startOf('week').format()).toBe(moment().locale('zh-cn').startOf('week').format())
})
})


Expand Down
1 change: 1 addition & 0 deletions test/plugin/weekOfYear.test.js
Expand Up @@ -22,4 +22,5 @@ it('Week of year', () => {
expect(dayjs().weeks(week).week()).toBe(moment().weeks(week).week())
expect(dayjs().weeks(-week).week()).toBe(moment().weeks(-week).week())
expect(dayjs().weeks(55).week()).toBe(moment().weeks(55).week())
expect(dayjs().weeks()).toBe(moment().weeks())
})

0 comments on commit 1295591

Please sign in to comment.