You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dddd parsing and defaults uses start of year instead of something closer to current time #2300
Looks like Moment defaults to the first week if there's week data present: https://github.com/moment/moment/blob/develop/moment.js#L1401. I can see how this seems wrong, but I'm curious what a better behavior would be. The next Thursday after the current time? The Thursday in the current week? The latter would be relatively easy to implement by just changing that default.
From reading the docs it seems defaults are supposed to be layered on top of current time by default, but as you say that still leaves the question as to whether it should be the day of week in the current week, or the day on which that day of week next falls. It feels to me like Thursday in the current week would be the closest match with the behaviour of the other defaults. I've worked around it in my own code for now by extracting the data I need out of the 1st January parse result and setting it explicitly on a new value with today's time.
I agree the docs are wrong (they're right for most cases, but Moment handles weekday/week/weekyear a bit separately from day/month/year). I think a pull request with appropriate tests that changes that default of 1 to the current week index would probably be accepted.
var d = moment('Thursday 8:30pm', ['dddd h:mm a'], 'en');
var d2 = d.format("YYYY Do MMMM dddd h:mm a");
produces
2015 1st January Thursday 8:30 pm
Which I found surprising given the documentation for defaults. Is this intended behaviour?