Skip to content

Commit 1295591

Browse files
committed
fix: Allow set start day of week in locale && Allow set week in weekOfYear plugin
1 parent 9ad732c commit 1295591

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

src/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ class Dayjs {
172172
return isStartOf ? instanceFactory(1, this.$M) :
173173
instanceFactory(0, this.$M + 1)
174174
case C.W: {
175-
const l = this.$locale()
176-
const weekStart = l && l.weekStart === 1 ? 1 : 0
175+
const weekStart = this.$locale().weekStart || 0
177176
return isStartOf ? instanceFactory(this.$D - (this.$W - weekStart), this.$M) :
178177
instanceFactory(this.$D + (6 - (this.$W - weekStart)), this.$M)
179178
}

src/locale/zh-cn.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const locale = {
88
months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_'),
99
monthsShort: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
1010
ordinal: n => `${n}日`,
11+
weekStart: 1,
1112
formats: {
1213
LT: 'HH:mm',
1314
LTS: 'HH:mm:ss',

test/manipulate.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import moment from 'moment'
22
import MockDate from 'mockdate'
33
import dayjs from '../src'
4+
import '../src/locale/zh-cn'
45

56
beforeEach(() => {
67
MockDate.set(new Date())
@@ -28,6 +29,10 @@ describe('StartOf EndOf', () => {
2829
expect(dayjs().startOf('otherString').valueOf()).toBe(moment().startOf('otherString').valueOf())
2930
expect(dayjs().endOf('otherString').valueOf()).toBe(moment().endOf('otherString').valueOf())
3031
})
32+
33+
it('StartOf week with locale', () => {
34+
expect(dayjs().locale('zh-cn').startOf('week').format()).toBe(moment().locale('zh-cn').startOf('week').format())
35+
})
3136
})
3237

3338

test/plugin/weekOfYear.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ it('Week of year', () => {
2222
expect(dayjs().weeks(week).week()).toBe(moment().weeks(week).week())
2323
expect(dayjs().weeks(-week).week()).toBe(moment().weeks(-week).week())
2424
expect(dayjs().weeks(55).week()).toBe(moment().weeks(55).week())
25+
expect(dayjs().weeks()).toBe(moment().weeks())
2526
})

0 commit comments

Comments
 (0)