Bug 17217 - make strptime("1","%m") work
Summary: make strptime("1","%m") work
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.3.*
Hardware: Other Linux
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2017-01-25 17:30 UTC by Frederick Eaton
Modified: 2017-01-25 17:30 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Frederick Eaton 2017-01-25 17:30:04 UTC
This a feature request corresponding to bug 17212.

Currently, 'strptime' returns NA if the format string contains a month specifier with no day-of-month specifier. This is confusing and not useful. Since no code will be expected to depend on this behavior, I suggest improving it in a backwards-compatible way.

- If the month is specified but no day, then a POSIXlt should be returned with the day set to 1.

- The documentation for "%m" specifier should point to NOTES or wherever the special behavior of months is documented. Similarly for "%Y".

- Currently, strptime returns the current month and day when only "%Y" is specified. Some programs may depend on this behavior. However, this has the same potential problems as "%m", since certain month/day combinations (i.e. Feb 29) may not be available in all years. Furthermore, having the output of 'strptime' depend on the current date can cause difficult-to-detect "zero-day" bugs which don't show up in testing. Users should be given the option of fixing this behavior with a new 'template' argument which provides a POSIXlt argument to be used as a template for the 'strptime' return value. E.g.:

    > strptime("7","%m",template=as.POSIXlt("1970-01-01",tz="UTC"))
    [1] "1970-07-01 UTC"
    > strptime("2001","%Y",template=as.POSIXlt("1970-01-01",tz="UTC"))
    [1] "2001-01-01 UTC"