Skip to content

dddd parsing and defaults uses start of year instead of something closer to current time #2300

Description

@rj33

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?

Activity

  1. icambron commented on Apr 1, 2015

    @icambron
    Contributor

    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.

  2. rj33 commented on Apr 1, 2015

    @rj33
    Author

    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.

  3. icambron commented on Apr 1, 2015

    @icambron
    Contributor

    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.

  4. ichernev commented on Aug 11, 2015

    @ichernev
    Contributor

    We should default to current week, as we default to current month/day. PRs welcome.

  5. maggiepint commented on Oct 3, 2016

    @maggiepint
    Member

    closed in favor of #3406

  6. added a commit that references this issue on Oct 20, 2016
    1fa8275
  7. added 2 commits that reference this issue on Nov 6, 2016
    20c140a
    47cffae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions