You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The make_datetime_100 function in the lubridate chapter does not seem to be entirely accurate. The timezone information is neglected while using the make_datetime function and this leads to the default timezone (UTC) being adopted for all datetimes created using this function. This is not a problem for the examples thereafter, but if one were to compare datetimes from different timezones, especially by using the arr_time and the sched_arr_time, the results would not be correct.
For example, if we were to print the arrival time of all flights according to the departure time zone, using something like the following
, it would not give the exepected results as the timezones all match in the first place, they are all UTC.
Similarly, if we were to create graphs based on the arrival times rather than the departure times as shown in the examples, one needs to be very careful about the interpretation, as the destinations are all in different timezones. This could also be explained, or simply, the creation of the arr_time and the sched_arr_time removed from the flights_dt data frame to avoid incorrect usage.
The accurate solution is perhaps to join the flights with the airports table which has a timezone column.
use the timezone as string info. Note: a group_by(timezone) is needed with with_tz when using this function. This is because with_tz is not vectorised.
make_datetime_100_tzone <- function(year, month, day, time, timezone) {
make_datetime(year, month, day, time %/% 100, time %% 100, tz = timezone)
}
create a function for composing the date and time when the time zone offset is known
make_datetime_100_tz <- function(year, month, day, time, tzoffset) {
make_datetime(year, month, day, time %/% 100, time %% 100) + hours(tzoffset)
}
Again, this is not really straightforward, as there are limitations to using this in further examples involving the time zone. A problem is while trying to use with_tz later on this datetime; as with_tz is not vectorised, results will not be as expected. (group_by, rowwise or purr seem to be workarounds). Perhaps it is simply better to omit the arrival times from the flights_dt data frame and keep the examples simple, until support for timezones is improved.
Thanks for your attention!
KS
The text was updated successfully, but these errors were encountered:
The make_datetime_100 function in the lubridate chapter does not seem to be entirely accurate. The timezone information is neglected while using the make_datetime function and this leads to the default timezone (UTC) being adopted for all datetimes created using this function. This is not a problem for the examples thereafter, but if one were to compare datetimes from different timezones, especially by using the arr_time and the sched_arr_time, the results would not be correct.
For example, if we were to print the arrival time of all flights according to the departure time zone, using something like the following
flights_dt %>%
mutate(arr_time_in_deptz = with_tz(arr_time, dep_time %>% tz()))
, it would not give the exepected results as the timezones all match in the first place, they are all UTC.
Similarly, if we were to create graphs based on the arrival times rather than the departure times as shown in the examples, one needs to be very careful about the interpretation, as the destinations are all in different timezones. This could also be explained, or simply, the creation of the arr_time and the sched_arr_time removed from the flights_dt data frame to avoid incorrect usage.
The accurate solution is perhaps to join the flights with the airports table which has a timezone column.
use the timezone as string info. Note: a group_by(timezone) is needed with with_tz when using this function. This is because with_tz is not vectorised.
make_datetime_100_tzone <- function(year, month, day, time, timezone) {
make_datetime(year, month, day, time %/% 100, time %% 100, tz = timezone)
}
create a function for composing the date and time when the time zone offset is known
make_datetime_100_tz <- function(year, month, day, time, tzoffset) {
make_datetime(year, month, day, time %/% 100, time %% 100) + hours(tzoffset)
}
Again, this is not really straightforward, as there are limitations to using this in further examples involving the time zone. A problem is while trying to use with_tz later on this datetime; as with_tz is not vectorised, results will not be as expected. (group_by, rowwise or purr seem to be workarounds). Perhaps it is simply better to omit the arrival times from the flights_dt data frame and keep the examples simple, until support for timezones is improved.
Thanks for your attention!
KS
The text was updated successfully, but these errors were encountered: