Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upforce_tz() should convert dates to date-times #675
Comments
|
I think the last two should return POSIX instead of date. I would qualify this as a bug. Do you also find the first example unexpected? This is a new addition in the last minor version to avoid dealing explicitly with the NULL tzs, but I am not entirely convinced it was such a good idea. |
|
I strongly recommend against up-converting dates to datetime in general, and I think doing so implicitly would be asking for trouble. The typical approach there is to assume the time is all-zeroes, but then I hadn't thought of it when I created this issue, but on reflection, yes I think the first result is unexpected, given that I have a non-UTC locale set. Would it make sense to drop timezones from time-free Potential problems might include edge cases like Samoa's missing day (https://zachholman.com/talk/utc-is-enough-for-everyone-right). |
|
You ask for an operation which makes sense on date-times, that implise that you are interpreting the date as an instant. Otherwise why would you do force_tz on a date?
Yes. I will revert it to NULL. |
|
I agree I'm happy to help with code, though I won't have time until at least tomorrow. Sounds like you want |
|
It seems reasonable to me to return POSIXct when you explicit request a timezone be added to a Date. Adding a tzone attribute to a Date object is definitely wrong: library(lubridate, warn.conflicts = FALSE)
tz(force_tz(today(), "America/New_York"))
#> [1] "UTC"
class(force_tz(today(), "America/New_York"))
#> [1] "Date"
tz(with_tz(today(), "America/New_York"))
#> [1] "America/New_York"
class(with_tz(today(), "America/New_York"))
#> [1] "Date"
tz(`tz<-`(today(), "America/New_York"))
#> [1] "UTC"
class(`tz<-`(today(), "America/New_York"))
#> [1] "Date"Created on 2019-11-20 by the reprex package (v0.3.0) (I agree that lubridate seems to upclass dates to date-times too readily; but that's a separate issue) |
Perhaps this is intentional, but it strikes me as unexpected:
Latest Github version, 1.7.4.
In general, timezones for pure
Dates seem to be discouraged in that virtually no lubridate functions will ever return a non-UTC date (e.g.today,as_date,date, etc.), but I can't find anything to this effect in the docs.