tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
733 stars 207 forks source link

Type inconsistency #400

Closed aphalo closed 8 years ago

aphalo commented 8 years ago

For consistency the code below should return a time NA instead of a date NA, as class(lubridate::ymd(NA_character_) apparently returned in the previous version.

class(lubridate::ymd(NA_character_, tzone = "UTC"))
[1] "Date"

I can fix package 'photobiology' by generating a suitable NA, with the code below, but this looks to me as a bug in 'lubridate'.

lubridate::ymd_hms(NA_character_, tzone = "UTC"))
aphalo commented 8 years ago

Mix up of use of ymd() and ymd_hms() in my code. It just happened to work earlier!

vspinu commented 8 years ago

The argument is tz. If you pass tzone="UTC" "UTC" will be parsed as date.

Mixing ymd and ymd_hmd should be working as expected (at least with lubridate). Most of base and lubridate date-time functionality is generic. The advantage or returning Date from ymd is that you won't get confused with time zones during date-time manipulation.

aphalo commented 8 years ago

Thanks! Code is working, and conceptually I am representing times. The error was caused because at some places in my code the logic tests whether the value supplied is of class time or not. I just submitted an update to my 'photobiology' package that also should "cure" the NOTEs triggered by other of my packages. Thanks for your help!