Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the weekStart option in locale file seens not work. #662

Closed
julywind opened this issue Aug 18, 2019 · 10 comments
Closed

the weekStart option in locale file seens not work. #662

julywind opened this issue Aug 18, 2019 · 10 comments

Comments

@julywind
Copy link

Describe the bug
A clear and concise description of what the bug is.

const dayjs = require('dayjs')
const weekday = require('dayjs/plugin/weekday')
const locale = {
  weekStart: 1
}
dayjs.locale(locale, null ,true)
dayjs.extend(weekday)

const d1 = dayjs().startOf('week')

const date = d1.toDate()
console.log(date, d1.weekday())

result is '2019-08-17T16:00:00.000Z 0'
Expected behavior
A clear and concise description of what you expected to happen.
2019-08-18T16:00:00.000Z 1

Information

  • Day.js Version [e.g. v1.0.0] 1.8.15
  • OS: [e.g. iOS] macOS
  • Browser [e.g. chrome 62] node test.js
  • Time zone: GMT+8 Asia/Shanghai
@julywind
Copy link
Author

julywind commented Aug 18, 2019

am i changing weekStart option in a right way?

@iamkun
Copy link
Owner

iamkun commented Aug 19, 2019

You are changing locale in the wrong way. Please check our docs and choose a build-in locale that week start on Monday.

@julywind
Copy link
Author

all the doc, I can find only this, "dayjs().startOf('week'); // 取决于 locale 文件里 weekStart 的值", but i don't know how to change it. could you help me to find it? thanks!

@iamkun
Copy link
Owner

iamkun commented Aug 19, 2019

@ghost
Copy link

ghost commented Aug 19, 2019

import from 'dayjs/locale/en-gb' // weekStart 1
 
dayjs.locale('en-gb').startOf('week').format()

@julywind
Copy link
Author

I wanna change the weekStart option only, not all the locale properties because it's one of my calendar options. It seems imposibble to do like that.
thank you very much!

@iamkun
Copy link
Owner

iamkun commented Aug 27, 2019

just import enLocale from 'dayjs/locale/en' and modify it to the config you want, and dayjs.locale(enLocale).

@robertwt7
Copy link

just import enLocale from 'dayjs/locale/en' and modify it to the config you want, and dayjs.locale(enLocale).

You're amazing! Fixed my issue. Thanks

@iamkun
Copy link
Owner

iamkun commented Aug 24, 2020

here's another solution #215 (comment)

@iamkun iamkun closed this as completed Aug 24, 2020
@bilal42011
Copy link

This en-gb locale startWeek property is 1 but it is not working ..Any solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants