Skip to content

Unexpected behavior of as_datetime for dates without seconds #1170

Open
@jobonaf

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions