Skip to content

should parse fail when out of range? #47

Open
@rnons

Description

Is this behavior expected?

var d3TimeFormat = require("d3-time-format")

d3TimeFormat.timeParse('%m/%d/%Y')('26/1/2017') // Fri Feb 01 2019 00:00:00 GMT+0900 (JST)
d3TimeFormat.timeParse('%d/%m/%Y')('26/1/2017') // Thu Jan 26 2017 00:00:00 GMT+0900 (JST)

I read from README %m - month as a decimal number [01,12]., so I would like d3TimeFormat.timeParse('%m/%d/%Y')('26/1/2017') to return null, is that possible?

Thank you.

Activity

ggmod

ggmod commented on Jul 18, 2018

@ggmod

I encountered the same issue. Looking at the d3 code it seems that actually it's the JavaScript Date constructor that is responsible for this behavior, and d3 just uses the Date constructor to create the final result.

I can't imagine how this behavior could ever be useful, and it certainly caused problems for me: in my use case when the user supplied data changed its format from month-day-year to day-month-year, my app produced nonsense results instead of throwing an error. I also wanted to use d3 for automatically detecting the format by trying out different patterns, but it can't distinguish between month-day-year and day-month-year because of this issue.

It would be great if d3 could validate if some fields are out of range, maybe using a flag for "extra strict" behavior.

mbostock

mbostock commented on Oct 23, 2019

@mbostock
Member

I think this would be difficult to implement, and I don’t have any current plans to support this feature, but it might make a good contribution if someone is interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      should parse fail when out of range? · Issue #47 · d3/d3-time-format