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
[C++] Add a strptime option to control the cutoff between 1900 and 2000 when %y #31951
When parsing to datetime a string with year in the short format ({}%y{}), it would be great if we could have control over the cutoff point between 1900 and 2000. Currently it is implicitly set to 68:
In the lubridate::fast_strptime() documentation it is described as follows:
cutoff_2000
integer. For y format, two-digit numbers smaller or equal to cutoff_2000 are parsed as though starting with 20, otherwise parsed as though starting with 19. {}Available only for functions relying on lubridates internal parser{}.
Dragoș Moldovan-Grünfeld / @dragosmg:
I think we would need to if we wanted to emulate the behaviour. I think it refers to the fact that other parsing functions in lubridate use the parsing functionality native to R (e.g. R's strptime as opposed to lubridate's {}fast_strptime){}.
I implemented this using the Arrow strptime kernel, but it would definitely be nice to have this option.
Having said that, it is not crucial, as the users can manipulate strings to add the first 2 digits and then parse with a "%Y-%m-%d" format.
I would expect an error when there is a mismatch between the string and the format, i.e. string has a short year ({}%y{}) and we try to parse using a long format ({}%Y{}). I think it would be much better to error or return a null in this situation.
Antoine Pitrou / @pitrou: @dragosmg On which platform is this? On non-Windows platforms, we basically defer to the platform's strptime function, so there is not much we can do to prevent this.
Antoine Pitrou / @pitrou:
Also, by reading the code, the vendored implementation we use on Windows (which was copied from the musl libc) probably shows the same lenient behaviour.
This issue has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this issue will be closed in 14 days. If this improvement is still desired but has no current owner, please add the 'Status: needs champion' label.
Activity
asfimport commentedon May 17, 2022
Antoine Pitrou / @pitrou:
"Available only for functions relying on lubridates internal parser" means we don't have to implement it, right?
asfimport commentedon May 17, 2022
Dragoș Moldovan-Grünfeld / @dragosmg:
I think we would need to if we wanted to emulate the behaviour. I think it refers to the fact that other parsing functions in lubridate use the parsing functionality native to R (e.g. R's
strptimeas opposed to lubridate's{}fast_strptime){}.I implemented this using the Arrow strptime kernel, but it would definitely be nice to have this option.
Having said that, it is not crucial, as the users can manipulate strings to add the first 2 digits and then parse with a
"%Y-%m-%d"format.asfimport commentedon May 18, 2022
Dragoș Moldovan-Grünfeld / @dragosmg:
Maybe related. I find the following unexpected:
I would expect an error when there is a mismatch between the string and the format, i.e. string has a short year (
{}%y{}) and we try to parse using a long format ({}%Y{}). I think it would be much better to error or return a null in this situation.asfimport commentedon May 19, 2022
Antoine Pitrou / @pitrou:
@dragosmg On which platform is this? On non-Windows platforms, we basically defer to the platform's
strptimefunction, so there is not much we can do to prevent this.asfimport commentedon May 19, 2022
Antoine Pitrou / @pitrou:
Interestingly, Python's own
strptimeimplementation catches this:asfimport commentedon May 19, 2022
Dragoș Moldovan-Grünfeld / @dragosmg:
@pitrou I'm on macOS.
asfimport commentedon May 19, 2022
Antoine Pitrou / @pitrou:
Also, by reading the code, the vendored implementation we use on Windows (which was copied from the musl libc) probably shows the same lenient behaviour.
asfimport commentedon May 19, 2022
Dragoș Moldovan-Grünfeld / @dragosmg:
Interesting, but the base R implementation behaves the same.
lubridateis a bit more robust though:github-actions commentedon Apr 2, 2026
This issue has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this issue will be closed in 14 days. If this improvement is still desired but has no current owner, please add the 'Status: needs champion' label.