Skip to content
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

Midnight timestamp not returning expected result #712

Closed
JegorG opened this issue Aug 30, 2018 · 6 comments
Closed

Midnight timestamp not returning expected result #712

JegorG opened this issue Aug 30, 2018 · 6 comments

Comments

@JegorG
Copy link

JegorG commented Aug 30, 2018

library(lubridate)

dmy_hm("Tuesday, 16 Mar 1999, 00:01")

"1999-03-16 00:01:00 UTC"

dmy_hm("1999-03-16 00:00:00 UTC")

"1999-03-16 UTC"

I expect

"1999-03-16 00:00:00 UTC"

@vspinu
Copy link
Member

vspinu commented Aug 30, 2018

You are confused about printed representation and actual object. These are not the same. Whenever in doubt use str.

@vspinu vspinu closed this as completed Aug 30, 2018
@challisd
Copy link

challisd commented Jan 17, 2019

You can get what you want with format(dmy_hm("1999-03-16 00:00:00 UTC"), "%Y-%m-%d %H:%M:%S %Z")

@challisd
Copy link

Also I agree with the original poster that this is a bug. I understand the underlying representation is currently the same, but if a user has a string with hours and minutes, parses it with a function called dmy_hm and then converts back to a string it is perfectly reasonable to expect you'll get back a string with hours and minutes. Technical justification aside, this is a bug in that it does not behave the way virtually all users will expect it to.

@vspinu
Copy link
Member

vspinu commented Jan 18, 2019

you'll get back a string with hours and minutes.

It's not a string that is returned but a POSIXct object. The issue here is that R prints the midnight POSIXct objects without the trailing 00:00:00 for the space efficiency reasons. It's not such a big deal to get used to this, or if you are really troubled by it, you could write your own print.POSIXct method and place it in .Rprofile. In any case it's not lubridate's issue, it's how R prints things.

@JBrocklyAnderson
Copy link

So does this mean that the 00:00:00 time value still exists in the cell?

@srlamunion
Copy link

So does this mean that the 00:00:00 time value still exists in the cell?

That is my question also. It doesn't appear to be when written to .csv for example. The cell shows just the date and not the trailing 00:00:00 to go with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants