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

Fixed week number calculation for non standard dow/doy combinations. #2188

Closed
wants to merge 3 commits into from
Closed

Fixed week number calculation for non standard dow/doy combinations. #2188

wants to merge 3 commits into from

Conversation

gregor-rayman
Copy link

For some non standard combination of dow and doy the computation of the week number would return a wrong week number. This pull request fixes the problem.

Also added tests for all 7*7 dow/doy combinations.

@usmonster
Copy link

If it works, this might fix #2115.

@usmonster
Copy link

I'm not sure this is a complete fix. You may need to also fix the logic in the weekOfYear method. Please see #2115 for a simple test.

@gregor-rayman
Copy link
Author

As mentioned in the discussion in #2115, this fix uses the way for dow, doy as used in moment.js

@ichernev
Copy link
Contributor

@gregor-rayman @usmonster I agree the current values are confusing, but I think that is being used by all localization software around, including CLDR.

What is the usecase for a start of week that doesn't exist in real life? :)

@gregor-rayman you also have to rebase to latest develop. Check https://github.com/moment/moment/blob/develop/CONTRIBUTING.md for more info.

@gregor-rayman
Copy link
Author

@ichernev, thanks, I will rebase today :)

The usecase for start of week that doesn't exist in real life is indeed useless. But grey is the theory and green is the tree of life, so I am quite certain that some companies use non-standard week numbering for their production rhythm. (e.g. some of our customers in Europe start their week on Saturday).

I don't have a problem with the slightly confusing settings, the problem I have that currently the parsing of weeks in the Arabic numbering produces wrong values - it shifts the week number by 1. This pull request fixes it. Thanks in advance for merging after I rebase.

@usmonster
Copy link

@ichernev Thanks for mentioning CLDR, though I've been looking for any other authoritative code or specification that defines doy (firstDay elsewhere) in the same way that moment does.

It does indeed seem odd and confusing that moment allows doy > 6 (docs say 0-15 are allowable values), so can you please point me to some code or docs other than moment that show or use these same semantics? Or a use case that shows when/why 0-6 as the sole allowable values are insufficient? (I don't want to hijack this thread, so please feel free to reply on #2115 if you get a chance--thanks in advance!)

@gregor-rayman
Copy link
Author

I have replaced this pull request with #2336 based on the current develop.

@gregor-rayman
Copy link
Author

Hi @ichernev, I just wanted to ask, whether the #2336 is ok to be merged?

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

Successfully merging this pull request may close these issues.

None yet

3 participants