-
Notifications
You must be signed in to change notification settings - Fork 214
Open
Description
Goal:
Convert 10-minute UTC observations to hourly local time for non standard timezones (i.e. UTC -0230)
Process tried:
10 minute UTC dates around DST change -> convert to local time using with_tz("America/St_Johns") -> round upwards to hourly using ceiling_date("hours") _> convert back to UTC using with_tz("UTC") to test
Issue:
- 2019-11-03 01:10 -0230 (2019-11-03 03:40 UTC) →
- rounded to 02:00 →
- interpreted as 02:00 -0330 (which is 2019-11-03 05:30 UTC, not 2019-11-03 04:30 UTC as expected)
System:
lubridate version 1.9.3, R version 4.4.1
Reprex:
input <- data.frame(
date_utc = lubridate::ymd_h("2019-11-03 05", tz = "UTC") +
lubridate::minutes((-15:3) * 10)
) |>
dplyr::mutate(
date_local = date_utc |> lubridate::with_tz("America/St_Johns"),
utc_offset = format(date_local, "%z")
)
input |>
dplyr::mutate(
date_local_ceiling = date_local |>
lubridate::ceiling_date("hours"),
utc_offset_ceiling = format(date_local_ceiling, "%z"),
date_ceiling_as_utc = date_local_ceiling |>
lubridate::with_tz("UTC"),
converted_utc_delta = difftime(date_ceiling_as_utc, date_utc, units = "mins") # should range from 50 mins to 0 mins
)
Output:
date_utc date_local utc_offset date_local_ceiling utc_offset_ceiling date_ceiling_as_utc converted_utc_delta
1 2019-11-03 02:30:00 2019-11-03 00:00:00 -0230 2019-11-03 00:00:00 -0230 2019-11-03 02:30:00 0 mins
2 2019-11-03 02:40:00 2019-11-03 00:10:00 -0230 2019-11-03 01:00:00 -0230 2019-11-03 03:30:00 50 mins
3 2019-11-03 02:50:00 2019-11-03 00:20:00 -0230 2019-11-03 01:00:00 -0230 2019-11-03 03:30:00 40 mins
4 2019-11-03 03:00:00 2019-11-03 00:30:00 -0230 2019-11-03 01:00:00 -0230 2019-11-03 03:30:00 30 mins
5 2019-11-03 03:10:00 2019-11-03 00:40:00 -0230 2019-11-03 01:00:00 -0230 2019-11-03 03:30:00 20 mins
6 2019-11-03 03:20:00 2019-11-03 00:50:00 -0230 2019-11-03 01:00:00 -0230 2019-11-03 03:30:00 10 mins
7 2019-11-03 03:30:00 2019-11-03 01:00:00 -0230 2019-11-03 01:00:00 -0230 2019-11-03 03:30:00 0 mins
8 2019-11-03 03:40:00 2019-11-03 01:10:00 -0230 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 110 mins
9 2019-11-03 03:50:00 2019-11-03 01:20:00 -0230 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 100 mins
10 2019-11-03 04:00:00 2019-11-03 01:30:00 -0230 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 90 mins
11 2019-11-03 04:10:00 2019-11-03 01:40:00 -0230 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 80 mins
12 2019-11-03 04:20:00 2019-11-03 01:50:00 -0230 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 70 mins
13 2019-11-03 04:30:00 2019-11-03 01:00:00 -0330 2019-11-03 01:00:00 -0230 2019-11-03 03:30:00 -60 mins
14 2019-11-03 04:40:00 2019-11-03 01:10:00 -0330 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 50 mins
15 2019-11-03 04:50:00 2019-11-03 01:20:00 -0330 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 40 mins
16 2019-11-03 05:00:00 2019-11-03 01:30:00 -0330 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 30 mins
17 2019-11-03 05:10:00 2019-11-03 01:40:00 -0330 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 20 mins
18 2019-11-03 05:20:00 2019-11-03 01:50:00 -0330 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 10 mins
19 2019-11-03 05:30:00 2019-11-03 02:00:00 -0330 2019-11-03 02:00:00 -0330 2019-11-03 05:30:00 0 mins
Metadata
Metadata
Assignees
Labels
No labels