Skip to content

Instantly share code, notes, and snippets.

@izahn
Last active May 11, 2023 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izahn/48a2fcd8a3a093d7f33cf3267a32db6f to your computer and use it in GitHub Desktop.
Save izahn/48a2fcd8a3a093d7f33cf3267a32db6f to your computer and use it in GitHub Desktop.
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

## example data
exd <- data.frame(
  depart = ymd_hms(c("1900-01-01 13:35:00", "1900-01-01 13:35:00")),
  arrive = ymd_hms(c("2023-03-10 14:30:00", "2023-03-13 13:30:00"))
  )
## the second departure clock time appears to be after the arrival clock time (ignoring the date)
exd
#>                depart              arrive
#> 1 1900-01-01 13:35:00 2023-03-10 14:30:00
#> 2 1900-01-01 13:35:00 2023-03-13 13:30:00

## but it is not, as we see once we convert to the correct time zone
exd$depart <- with_tz(exd$depart, tzone = "US/Eastern")
exd$arrive <- with_tz(exd$arrive, tzone = "US/Eastern")
exd
#>                depart              arrive
#> 1 1900-01-01 08:35:00 2023-03-10 09:30:00
#> 2 1900-01-01 08:35:00 2023-03-13 09:30:00

Created on 2023-05-11 with reprex v2.0.2

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