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
incorrect weekOfYear
for certain dow/doy combos
#2115
Comments
weekOfYear
way off for certain dow/doy combosweekOfYear
for certain dow/doy combos
Any thoughts? This affects many locales where the first day of the week is not Sunday or Monday. If the bug is verified, should I submit a pull request for a better |
I have to admit, that the I have added a test with |
Do you mean |
No, I have meant The bug was actually not in the calculation of the week from the date, just in the other direction. |
Whoa, if that's the case, then have been misunderstanding Indeed, according to the docs Just to help me understand, can you explain why it is 12 and not 1? And what would a |
I found a good explanation, which makes it more obvious what @icambron, can you chime in, please? Is there a link to somewhere that explains this more fully than the docs currently do? |
@usmonster It's been a long time since I looked at this, but off the top of my head...yeah, I don't get it either. Sorry I can't be more helpful. Whenever I wrote the linked explanation, I had just written a bunch of Moment's implementation for handling weeks, so I probably understood it then, but that explanation doesn't seem to jive with |
I cannot explain the reasoning for the way, how So, if January 1st must belong to the week No. 1 and Saturday is the first day of the week, then |
Ah, if it's implemented this way, I think it's a problem with the implementation. No other definition I've seen (i.e. ISO, Unicode TR35) defines week-of-year calculation like this. The comments in the API don't even hint that this is what's going on, though now I notice that tests have been written that assume this very logic, e.g., I see lines like this: dow : 1, // Monday is the first day of the week.
doy : 7 // The week that contains Jan 1st is the first week of the year. And in another file: dow : 6, // Saturday is the first day of the week.
doy : 12 // The week that contains Jan 1st is the first week of the year. So your assessment of the implementation looks accurate. Still, it just feels icky, as if the tests were written to match a broken implementation. This is especially frustrating since a cleaner thing to do would have been to just fix the implementation so that it does what's intuitive (take the " An alternative would be to deprecate Any thoughts? |
Well as far as I can tell we had the code set up for iso weeks, then we kind of abused the fact and made sure the numbers made it work. If we change the semantics to be somethig more meaningful to users it might be better. But it should be backwards compatible (so new methods expose new numbers). As of your example, you can make it work if you add 7 a few times to doy, because its relative to dow. |
Closing this in favor of #2336 |
Hello @ichernev. :) Coming back to this a year later, I'm still in favor of implementing more meaningful semantics, though I'm almost certain it is not possible to do something backwards compatible without also changing syntax.
I'm not convinced this is always the case.. For example, Where should I search for more feedback on this? This particular issue is closed, though I can move the conversation to moment/momentjs.com#279 or open a new issue if it's more appropriate. |
I'd also like to bump this, as I spent an extra day trying to figure out how |
It appears the week calculation algorithm isn't generic enough, as it seems to handle certain dow/doy combinations incorrectly:
I assume something's a bit off in the
weekOfYear
function, unless I'm doing something wrong?The text was updated successfully, but these errors were encountered: