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

discrepancy between strptime and ymd #289

Closed
markvanderloo opened this Issue Dec 16, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@markvanderloo

markvanderloo commented Dec 16, 2014

ymd's doc states that it is based on 'strptime'. However, for the edge case of a non-existing date I get different results.

> ymd("2011-02-29")
[1] "2011-03-01 UTC"
> strptime("2011-02-29","%Y-%m-%d")
[1] NA
@vspinu

This comment has been minimized.

Show comment
Hide comment
@vspinu

vspinu Dec 18, 2014

Member

ymd's doc states that it is based on 'strptime'.

This used to be true but it's not anymore. ymd relies only strptime when non-numeric formats are used. Otherwise a fast internal parser is used. This is documented in parse_date_time:

 ‘parse_date_time’, and hence all the derived functions, such as
 ‘ymd_hms’, ‘ymd’ etc, will drop into ‘fast_strptime’ instead of
 ‘strptime’ whenever the trained from input data formats are all
 numeric.

I have just fixed this in the docs. Thanks.

ymd("2011-02-29") ## [1] "2011-03-01 UTC"

This is a semi-bug. I will fix this in the parser if it doesn't impose too much of the penalty. You are expected not to pass invalid dates to the parser.

Member

vspinu commented Dec 18, 2014

ymd's doc states that it is based on 'strptime'.

This used to be true but it's not anymore. ymd relies only strptime when non-numeric formats are used. Otherwise a fast internal parser is used. This is documented in parse_date_time:

 ‘parse_date_time’, and hence all the derived functions, such as
 ‘ymd_hms’, ‘ymd’ etc, will drop into ‘fast_strptime’ instead of
 ‘strptime’ whenever the trained from input data formats are all
 numeric.

I have just fixed this in the docs. Thanks.

ymd("2011-02-29") ## [1] "2011-03-01 UTC"

This is a semi-bug. I will fix this in the parser if it doesn't impose too much of the penalty. You are expected not to pass invalid dates to the parser.

@vspinu vspinu added the bug label Dec 18, 2014

@vspinu vspinu closed this in 8521eb5 Apr 27, 2015

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