Skip to content

Parsing week numbers using d3.time.format #1914

Closed

Description

@mchinosi

Hi.
I have a problem parsing weeks.
I'm using d3 v3.4.8.
I have dates in a format like 2014-19 - but the format is not a problem, since I have the same problem using 2014(19), 2014 19 and so on...
Is it possible to parse such string using $Y-$W or $Y-$U? e.g.

d3.time.format('%Y-%W').parse('2014-19');

Because I obtain as a result always the date corresponding to the 1st of January 2014

Date {Wed Jan 01 2014 00:00:00 GMT+0100}

I'm also parsing months, years, days and it works well. Only weeks are not working.

Thank you
Michele

Activity

  1. mchinosi commented on Jun 16, 2014

    @mchinosi
    Author

    Actually, there is a workaround, but I'd need to manually add also %w with value 0. E.g.

    // I'm getting from elsewhere the 'x' variable, a date in the format YYYY(WW)
    x = d3.time.format('%Y-%W-%w').parse(w.replace(/([0-9]{4})\(([0-9]{2})\)/g,"$1-$2-0"));

    Thank you

  2. jasondavies commented on Jun 16, 2014

    @jasondavies
    Contributor

    Yes, at the moment we require the day-of-week (%w) for the week-of-year (%U or %W) to be parsed. I don’t see any particular reason why we can’t drop that requirement and use suitable defaults.

  3. added this to the 3.4.x milestone on Oct 9, 2014
  4. modified the milestones: 3.4.x, 3.5.x on Nov 10, 2014
  5. added
    bug
    and removed on Oct 22, 2015
  6. modified the milestones: 3.5.7, 3.5.x on Oct 22, 2015
  7. mbostock commented on Nov 8, 2015

    @mbostock
    Member

    New behavior:

    > d3.time.format('%Y-%W').parse('2014-19');
    Mon May 12 2014 00:00:00 GMT-0700 (PDT)
    > d3.time.format('%Y-%U').parse('2014-19');
    Sun May 11 2014 00:00:00 GMT-0700 (PDT)
    
  8. added a commit that references this issue on Nov 8, 2015
    e9472ba
  9. mbostock commented on Nov 8, 2015

    @mbostock
    Member

    Fix staged in #2591 for 3.5.7.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions