-
Notifications
You must be signed in to change notification settings - Fork 109
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
date_format does not work correctly on hms objects #88
Comments
If I understand correctly the issue here is that library(hms)
library(scales)
t <- Sys.time()
date_format("%H:%M", tz = "GMT")(t)
#> [1] "17:22"
date_format("%H:%M", tz = "GMT")(as.hms(t))
#> [1] "17:22:08.155499"
format(t, "%H:%M", tz = "GMT")
#> [1] "17:22"
format(as.hms(t), "%H:%M", tz = "GMT")
#> [1] "17:22:08.155499"
|
We should probably add support for hms. |
So this is caused because the Assuming we want to fix this in scales without adjusting the This fix of course stops making sense when a user provides an hms object and asks for a format containing dates not just hours minutes and seconds (as is currently the default for |
I'd rewrite date_format <- function(format = "%Y-%m-%d", tz = 'UTC') {
function(x) {
if (inherits(x, "POSIXt")) {
format(x, format, tz = tz)
} else if (inherits(x, "Date")) {
} else if (inherits(x, "difftime")) {
} else {
stop("Unsupported type (needs better error message)")
}
}
} Alternatively, it might be better to add a custom time format type — it's a bit odd to use |
As the function is called "date_format" behaving like "format" is perhaps the right behaviour.
Is this perhaps rather an issue with the hms library which should implement some kind of format method?
The text was updated successfully, but these errors were encountered: