-
Notifications
You must be signed in to change notification settings - Fork 207
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
Add make_date() feature for converting date-times into dates #355
Comments
This seems more like a bug in base R, in my opinion. |
I also think this should be addressed in base R. No need to duplicate existent functions. Would you bother firing a bug report? I think |
I’m pretty sure this will not be seen as bug by R Core. It’s documented and intentional. While I (and we) see it as a bug/misfeature, I see no chance of the default behaviour being changed in R base. So the only chance of having a widely-used sensible and consistent datetime-to-date function would be having such a function in the lubridate package. (Of course, this is not a required function, as it’s easy to work around, but it would be very helpful having it as a convenience function. I like convenience functions. ☺) |
@huftis This annoys me greatly. I will submit a pull request. |
I propose adding a convenience function
make_date()
for converting date-times to dates. One might by tempted to useas.Date()
, and this works in many cases, but with the default options it gives surprising results in a few cases. Example:x1 = as.POSIXct("2010-08-03 00:59:59.23")
x2 = as.POSIXct("2010-08-03 00:59:59.23", tz="Europe/London")
x3 = as.POSIXct("2010-11-03 00:59:59.23")
x4 = as.POSIXct("2010-11-03 00:59:59.23", tz="Europe/London")
The naïve user might expect
as.Date()
to return the 3rd of the month (August/November) for all ofx1
–x4
. However, on my system (aEurope/Oslo
timezone), I get:It’s even more surprising if you have already used
floor_date(x, "day")
on the objects to remove the ‘time’ part.The way to get the correct date (
Date
) corresponding to a date-time is eitheras.Date(format(x, "%Y-%m-%d"))
or (preferably)as.Date(x, tz=attr(x, "tzone"))
:So I propose adding such a convenience function
make_date()
tolubridate
, that would runfor
POSIXct
andPOSIXlt
objects (and just returnx
forDate()
objects).I just based the name on the
make_difftime()
function; other names may better.The text was updated successfully, but these errors were encountered: