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

Why does R switch from PDT to PST at 1:36:14 and not at 2:00:00 #33

Open
aylapear opened this issue Nov 8, 2023 · 0 comments
Open

Why does R switch from PDT to PST at 1:36:14 and not at 2:00:00 #33

aylapear opened this issue Nov 8, 2023 · 0 comments

Comments

@aylapear
Copy link
Member

aylapear commented Nov 8, 2023

I would have expected the switch from PDT to PST to occur at 2:00:00 but it is clear that this switch occurs between "2021-11-07 01:36:14" and "2021-11-07 01:36:15". Need to investigate into time theory and see why this change occurs in R at this exactly moment.

dttr2 and base R have the same behaviour on this but lubridate absolutely fails at this as it has set every

> x <- c("2021-11-07 1:00:00", "2021-11-07 1:00:01", "2021-11-07 1:35:00", "2021-11-07 1:36:00", "2021-11-07 1:36:10", "2021-11-07 1:36:14", "2021-11-07 1:36:15", "2021-11-07 1:36:30", "2021-11-07 1:36:59", "2021-11-07 1:45:00", "2021-11-07 1:59:59", "2021-11-07 2:00:00", "2021-11-07 2:30:00") 

> # dttr2
> x_pst <- dtt_date_time(x, tz = "PST8PDT")
> x_pst
 [1] "2021-11-07 01:00:00 PDT" "2021-11-07 01:00:01 PDT" "2021-11-07 01:35:00 PDT" "2021-11-07 01:36:00 PDT" "2021-11-07 01:36:10 PDT"
 [6] "2021-11-07 01:36:14 PDT" "2021-11-07 01:36:15 PST" "2021-11-07 01:36:30 PST" "2021-11-07 01:36:59 PST" "2021-11-07 01:45:00 PST"
[11] "2021-11-07 01:59:59 PST" "2021-11-07 02:00:00 PST" "2021-11-07 02:30:00 PST"

# base R
> x_pst <- as.POSIXct(x, tz = "PST8PDT")
> x_pst
 [1] "2021-11-07 01:00:00 PDT" "2021-11-07 01:00:01 PDT" "2021-11-07 01:35:00 PDT" "2021-11-07 01:36:00 PDT" "2021-11-07 01:36:10 PDT"
 [6] "2021-11-07 01:36:14 PDT" "2021-11-07 01:36:15 PST" "2021-11-07 01:36:30 PST" "2021-11-07 01:36:59 PST" "2021-11-07 01:45:00 PST"
[11] "2021-11-07 01:59:59 PST" "2021-11-07 02:00:00 PST" "2021-11-07 02:30:00 PST"

# lubridate
> x_pst <- lubridate::as_datetime(x, tz = "PST8PDT")
> x_pst
 [1] "2021-11-07 01:00:00 PST" "2021-11-07 01:00:01 PST" "2021-11-07 01:35:00 PST" "2021-11-07 01:36:00 PST" "2021-11-07 01:36:10 PST"
 [6] "2021-11-07 01:36:14 PST" "2021-11-07 01:36:15 PST" "2021-11-07 01:36:30 PST" "2021-11-07 01:36:59 PST" "2021-11-07 01:45:00 PST"
[11] "2021-11-07 01:59:59 PST" "2021-11-07 02:00:00 PST" "2021-11-07 02:30:00 PST"
> x_pst <- lubridate::ymd_hms(x, tz = "PST8PDT")
> x_pst
 [1] "2021-11-07 01:00:00 PST" "2021-11-07 01:00:01 PST" "2021-11-07 01:35:00 PST" "2021-11-07 01:36:00 PST" "2021-11-07 01:36:10 PST"
 [6] "2021-11-07 01:36:14 PST" "2021-11-07 01:36:15 PST" "2021-11-07 01:36:30 PST" "2021-11-07 01:36:59 PST" "2021-11-07 01:45:00 PST"
[11] "2021-11-07 01:59:59 PST" "2021-11-07 02:00:00 PST" "2021-11-07 02:30:00 PST"
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