iamkun / iamkun/dayjs

The `startOf` method is not using the current locale when the `timezone` plugin is enabled

Open
#2,394 1 comment 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
48.7k
Forks
2.8k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

I am one of the maintainer of the MUI Date and Time Pickers which are using dayjs for date manipulation.
One of our users reported a bug when using both the timezone and the de locale.

The problem comes from the startOf methods which is not using the current locale when the timezone plugin is enabled.

If you take the following piece of code:

dayjs.tz('2022-04-17', 'Europe/Paris').locale('de').startOf('week')

The returned day is a Sunday but it should be a Monday.

Expected behavior

The timezone plugin should not impact the behavior of startOf('week').

I was able to make the plugin work by setting the locale explicitly on this line:

https://github.com/iamkun/dayjs/blob/a9d7d0398d22ebd4bfc3812ca0134a97606d54d9/src/plugin/timezone/index.js#L123

Information

  • Day.js Version: 1.11.9
  • OS: Ubuntu 22.04.2
  • Browser: Chrome 115
  • Time zone: Europe/Paris

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/plugin/timezone/index.js at the referenced line and reproduce the supplied locale, timezone, and startOf('week') example. Trace how the timezone plugin creates or preserves locale state, then verify that the result uses Monday for the German locale without changing other startOf behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.