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 behaviour converting PST8PDT to Etc/GMT+8 #28

Open
sebdalgarno opened this issue Jul 21, 2023 · 2 comments
Open

unexpected behaviour converting PST8PDT to Etc/GMT+8 #28

sebdalgarno opened this issue Jul 21, 2023 · 2 comments
Assignees

Comments

@sebdalgarno
Copy link
Member

sebdalgarno commented Jul 21, 2023

I ran into this issue while converting a real world discharge data set that was provided in PST8PDT (i.e. two 1:00:00 entries on November 07 2021). I had to manually change the second 1:00:00 entry prior to adjusting tz, which doesn't seem right...

# a date time on the eve of end of daylight savings time
x <- dtt_date_time("2021-11-06 23:00:00", tz = "PST8PDT")

# dttr2 (magically) does this correctly - assigns the first 1:00 to PDT and the second 1:00 to PST
x_dtt <- reduce(map(1:4, function(y) dtt_add_hours(x, y)), c)
x_dtt

# note this is better behaviour than lubridate so far!

# we can then successfully convert to GMT and keep the sequence
dtt_adjust_tz(x_dtt, "ETC/GMT+8")

# but when we set the tz on a vector it assigns both 1:00 to PDT
x <- c("2021-11-06 00:00:00", "2021-11-07 1:00:00", "2021-11-07 1:00:00", "2021-11-07 2:00:00")
x_pst <- dtt_date_time(x, tz = "PST8PDT")
x_pst
# same like this
x_pst <- dtt_date_time(x) |> dtt_set_tz("PST8PDT")
x_pst

# which causes this to fail (i.e. should be a continuous sequence)
dtt_adjust_tz(x_pst, tz = "ETC/GMT+8")

# to resolve we have to add an hour to the second 1:00
x_pst[3] <- dtt_add_hours(x_pst[3], 1)
dtt_adjust_tz(x_pst, tz = "ETC/GMT+8")

@sebdalgarno sebdalgarno changed the title incorrect conversion between PST8PDT and Etc/GMT+8 unexpected conversion of PST8PDT to Etc/GMT+8 Jul 21, 2023
@sebdalgarno sebdalgarno changed the title unexpected conversion of PST8PDT to Etc/GMT+8 unexpected behaviour converting PST8PDT to Etc/GMT+8 Jul 21, 2023
@aylapear
Copy link
Member

aylapear commented Nov 8, 2023

This behaviour does match the intention of the function since a vector of strings is passed there is no way to tell whether the value should be PST or PDT if the values are independent (not a series). This means that the PST or PDT needs to be assigned consistently to string values and it appears that "2021-11-07 1:00:00" is coded with PDT and "2021-11-07 2:00:00" is coded with PST. This is unfortunately a limitation but is unavoidable when converting a string based on how time/timezones/daylight savings works.

This scenario can be common with various types of data and so users need to be aware of this issue.

@aylapear
Copy link
Member

aylapear commented Nov 8, 2023

Potential work arounds could be

  1. a function that can detect when this occurs in a data set so a person can manually make the change and confirm it was done correctly
  2. a function that can identify and make the correction

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

3 participants