Skip to content

Commit

Permalink
add setting start day of a week in locale (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
JennieJi authored and iamkun committed Feb 5, 2019
1 parent 142b763 commit 209a5f2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/en/I18n.md
Expand Up @@ -81,6 +81,7 @@ const localeObject = {
weekdays: 'Domingo_Lunes ...'.split('_'), // weekdays Array
weekdaysShort: 'Sun_M'.split('_'), // OPTIONAL, short weekdays Array, use first three letters if not provided
weekdaysMin: 'Su_Mo'.split('_'), // OPTIONAL, min weekdays Array, use first two letters if not provided
weekStart: 1, // OPTIONAL, set the start of a week. If the value is 1, Monday will be the start of week instead of Sunday。
months: 'Enero_Febrero ... '.split('_'), // months Array
monthsShort: 'Jan_F'.split('_'), // OPTIONAL, short months Array, use first three letters if not provided
ordinal: n => `${n}º`, // ordinal Function (number) => return number + output
Expand Down
1 change: 1 addition & 0 deletions docs/ja/I18n.md
Expand Up @@ -83,6 +83,7 @@ const localeObject = {
weekdays: 'Domingo_Lunes ...'.split('_'), // 曜日の配列
weekdaysShort: 'Sun_M'.split('_'), // OPTIONAL, short weekdays Array, use first three letters if not provided
weekdaysMin: 'Su_Mo'.split('_'), // OPTIONAL, min weekdays Array, use first two letters if not provided
weekStart: 1, // OPTIONAL, 最初の曜日を指定する。0は日曜日です。1は月曜日です。
months: 'Enero_Febrero ... '.split('_'), // 月の配列
monthsShort: 'Jan_F'.split('_'), // OPTIONAL, short months Array, use first three letters if not provided
ordinal: n => `${n}º`, // 序数 Function (number) => return number + output
Expand Down
1 change: 1 addition & 0 deletions docs/ko/I18n.md
Expand Up @@ -81,6 +81,7 @@ const localeObject = {
weekdays: 'Domingo_Lunes ...'.split('_'), // weekdays Array
weekdaysShort: 'Sun_M'.split('_'), // OPTIONAL, short weekdays Array, use first three letters if not provided
weekdaysMin: 'Su_Mo'.split('_'), // OPTIONAL, min weekdays Array, use first two letters if not provided
weekStart: 1, // OPTIONAL, set the start of a week. If the value is 1, Monday will be the start of week instead of Sunday。
months: 'Enero_Febrero ... '.split('_'), // months Array
monthsShort: 'Jan_F'.split('_'), // OPTIONAL, short months Array, use first three letters if not provided
ordinal: n => `${n}º`, // ordinal Function (number) => return number + output
Expand Down
1 change: 1 addition & 0 deletions docs/pt-br/I18n.md
Expand Up @@ -81,6 +81,7 @@ const objetoLocale = {
weekdays: 'Domingo_Lunes ...'.split('_'), // dias da semana: Array
weekdaysShort: 'Sun_M'.split('_'), // OPCIONAL, dias da semana com nome curto: Array, utiliza as três primeiras letras se nenhuma for especificada
weekdaysMin: 'Su_Mo'.split('_'), // OPCIONAL, dias da semana com nome mínimo: Array, utiliza as duas primeiras letras se nenhuma for especificada
weekStart: 1, // OPTIONAL, set the start of a week. If the value is 1, Monday will be the start of week instead of Sunday。
months: 'Enero_Febrero ... '.split('_'), // meses: Array
monthsShort: 'Jan_F'.split('_'), // OPCIONAL, meses com nome curto: Array, utiliza as três primeiras letras se nenhuma for especificada
ordinal: n => `${n}º`, // ordinal: Function (number) => retorna number + saída
Expand Down
1 change: 1 addition & 0 deletions docs/zh-cn/I18n.md
Expand Up @@ -81,6 +81,7 @@ const localeObject = {
weekdays: 'Domingo_Lunes ...'.split('_'), // 星期 Array
weekdaysShort: 'Sun_M'.split('_'), // 可选, 短的星期 Array, 如果没提供则使用前三个字符
weekdaysMin: 'Su_Mo'.split('_'), // 可选, 最短的星期 Array, 如果没提供则使用前两个字符
weekStart: 1, // 可选,指定一周的第一天。默认为0,即周日。如果为1,则周一为一周得第一天。
months: 'Enero_Febrero ... '.split('_'), // 月份 Array
monthsShort: 'Jan_F'.split('_'), // 可选, 短的月份 Array, 如果没提供则使用前三个字符
ordinal: n => `${n}º`, // 序号生成工厂函数 Function (number) => return number + output
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Expand Up @@ -171,9 +171,12 @@ class Dayjs {
case C.M:
return isStartOf ? instanceFactory(1, this.$M) :
instanceFactory(0, this.$M + 1)
case C.W:
return isStartOf ? instanceFactory(this.$D - this.$W, this.$M) :
instanceFactory(this.$D + (6 - this.$W), this.$M)
case C.W: {
const l = this.$locale()
const weekStart = l && l.weekStart === 1 ? 1 : 0
return isStartOf ? instanceFactory(this.$D - (this.$W - weekStart), this.$M) :
instanceFactory(this.$D + (6 - (this.$W - weekStart)), this.$M)
}
case C.D:
case C.DATE:
return instanceFactorySet('setHours', 0)
Expand Down
4 changes: 4 additions & 0 deletions test/manipulate.test.js
Expand Up @@ -20,6 +20,10 @@ describe('StartOf EndOf', () => {
})
})

it('StartOf EndOf Week with week start setting', () => {
expect(dayjs().locale({ name: 'test', weekStart: 1 }).startOf('week').valueOf()).toBe(moment().startOf('week').add(1, 'day').valueOf())
})

it('StartOf EndOf Other -> no change', () => {
expect(dayjs().startOf('otherString').valueOf()).toBe(moment().startOf('otherString').valueOf())
expect(dayjs().endOf('otherString').valueOf()).toBe(moment().endOf('otherString').valueOf())
Expand Down

0 comments on commit 209a5f2

Please sign in to comment.