-
Notifications
You must be signed in to change notification settings - Fork 18
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
POSIXct to Date conversion could use timezone #49
Comments
Dates do not have timezones. R> str(Sys.Date())
Date[1:1], format: "2017-02-07"
R> unlist(Sys.Date())
[1] "2017-02-07"
R> I intend to close this. If you do need a timezone with what really is a date, you can turn it back into |
they don't carry the timezone attribute but converting to Date can require one tzone <- "America/New_York"
x <- as.POSIXct("2017-01-01 19:00",tzone)
as.Date(x)
# "2017-01-02"
as.Date(x,tzone)
# "2017-01-01" see |
We convert to Date at the C++ level now. But yes, I see two stragglers on lines 161 and 184 -- and I see your point. I never used to use |
yep, those are the lines. looks to me like POSIXct isn't converted to date in C++ like character is though tzone <- "America/New_York"
x <- as.POSIXct("2017-01-01 19:00",tzone)
y <- anytime:::anytime_cpp(x,tzone,asDate=T)
str(y)
# POSIXct[1:1], format: "2017-01-01 19:00:00"
z <- anytime:::anytime_cpp(as.character(x),tzone,asDate=T)
str(z)
# Date[1:1], format: "2017-01-01" |
I don't follow. Look at
Exactly what are you expecting if not |
Maybe I'm misunderstanding the function, but I guess I'm expecting tzone <- "America/New_York"
anydate(as.POSIXct("2017-01-01 19:00",tzone),tzone)
# "2017-01-01" doesn't actually happen just like I would expect anydate("2017-01-01 19:00",tzone)
# "2017-01-01" does happen If you agree, you could either change |
This works, the rest appears to be your made up problem: R> anytime("2017-01-01 19:00")
[1] "2017-01-01 19:00:00 CST"
R> anydate("2017-01-01 19:00")
[1] "2017-01-01"
R> |
> anydate(anytime("2017-01-01 19:00"))
[1] "2017-01-02" does this seem right to you? |
Your call makes no sense to start with. Why envelop them? It's a usage error AFAICT.
|
because I have a vector of class POSIXct and I want to convert it to Date. It seemed to me that that intention of your package was to simplify/speed up all the back and forth formatting when parsing/converting in R. yes I could obviously do > x <- as.POSIXct("2017-01-01 19:00","America/New_York")
> as.Date(format(x,"%F"))
[1] "2017-01-01" by why are you opposed to something like > anydate(x)
[1] "2017-01-02" #what it currently returns
# vs:
> anydate(x)
[1] "2017-01-01" #what it should return ?? |
Why I am going to lock this now. If you continue to have basic R questions, consider Stackoverflow or the help lists. |
Your whole confusion is due to the fact that R> as.Date(x <- as.POSIXlt("2017-01-01 19:00","America/New_York"), tzone="America/New_York")
[1] "2017-01-01"
R>
R> as.Date(x <- as.POSIXlt("2017-01-01 19:00","America/New_York"))
[1] "2017-01-01"
R>
R> as.Date(x <- as.POSIXlt("2017-01-01 19:00"))
[1] "2017-01-01"
R> But these are known quirks in Base R and, while esoteric, have nothing to do with my package. The |
Change applied in #50 though |
anydate()
seems to be missing the timezone argument toas.Date()
internally ...utcdate()
should also be changedThanks for the awesome package!
The text was updated successfully, but these errors were encountered: