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

Unexpected behavior of as_datetime for dates without seconds #1170

Open
jobonaf opened this issue Oct 31, 2024 · 0 comments
Open

Unexpected behavior of as_datetime for dates without seconds #1170

jobonaf opened this issue Oct 31, 2024 · 0 comments

Comments

@jobonaf
Copy link

jobonaf commented Oct 31, 2024

Description

Problem
When using as_datetime() in lubridate, I noticed that for dates without specified seconds, the returned result is incorrect and does not match the expected timestamp.

Expected Behavior
I expect as_datetime() to maintain the specified date and time regardless of whether seconds are provided. The date 2009-05-10 23:59 should result in "2009-05-10 23:59:00 UTC".

Actual Behavior
When as_datetime() is applied to "2009-05-10 23:59", the result is 2020-09-05 10:23:59 UTC, which is entirely shifted. This behavior does not occur if seconds are included:

# Problematic case (no seconds)
lubridate::as_datetime("2009-05-10 23:59")
#> [1] "2020-09-05 10:23:59 UTC"  # Unexpected output

# No issue (seconds provided)
lubridate::as_datetime("2009-05-10 23:59:45")
#> [1] "2009-05-10 23:59:45 UTC"  # Expected output

Impact

This behavior can lead to significant errors when processing datetime data without seconds. It appears that the function might be misinterpreting input.

Context

Working environment:

  • R version: 3.5.2 (2018-12-20)
  • Platform: x86_64-pc-linux-gnu (64-bit), running on CentOS Linux 7 (Core)
  • Locale: LC_CTYPE=en_US.UTF-8, LC_TIME=en_US.UTF-8, LC_COLLATE=en_US.UTF-8, etc.
  • lubridate version: 1.9.3
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

1 participant