anytime
anytime copied to clipboard
anytime() sometimes returns the wrong date
For dates older than 15ish years ago, the anytime() function sometimes returns 11 pm on the day before the correct date.
OS: Windows 10.
Examples of the function returning the day before:
> anytime::anytime("November 1, 2005")
[1] "2005-10-31 23:00:00 EST"
> anytime::anytime("November 1, 2000")
[1] "2000-10-31 23:00:00 EST"
Examples of it returning the correct date:
> anytime::anytime("November 1, 2019")
[1] "2019-11-01 EDT"
> anytime::anytime("November 1, 2010")
[1] "2010-11-01 EDT"
(Edited by DEdd. for proper markdown formatting)
That is likely build / OS dependent via the system time zone library; I have no control over the one in the Windows build.
> anytime::anytime(c("Nov 1, 2000", "Nov 1, 2005", "Nov 1, 2010", "Nov 1, 2019"))
[1] "2000-11-01 CST" "2005-11-01 CST" "2010-11-01 CDT" "2019-11-01 CDT"
>
Note, however, that many releases ago we also added an alternate second parser using the R engine so maybe try that?
> anytime::anytime(c("2000-11-01", "2005-11-01", "2010-11-01", "2019-11-01"), useR=TRUE)
[1] "2000-11-01 CST" "2005-11-01 CST" "2010-11-01 CDT" "2019-11-01 CDT"
>
Lastly, anytime always returns a POSIXct object; and its default format omits hours and minutes at midnight; anydate may be what you wanted here all along if you wanted a Date object.
so maybe try that
... because R ships its own timezone db which may help you when you OS leaves you in the dark as above.