Skip to content
Prev 390888 / 398506 Next

Time Zone problems: midnight goes in; 8am comes out

It seems like the current version of lubridate is 1.8.0, which does
raise a warning for an invalid timezone, just like as.POSIXct. This is
what I tried:


print(lubridate::parse_date_time("1970-01-01 00:01:00",          "ymd
HMS"          , tz = "PST"))
print(as.POSIXct                ("1970-01-01 00:01:00", format =
"%Y-%m-%d %H:%M:%S", tz = "PST"))


outputs:
[1] "1970-01-01 08:01:00 GMT"
Warning message:
In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'PST'
[1] "1970-01-01 00:01:00 GMT"
Warning messages:
1: In strptime(x, format, tz = tz) : unknown timezone 'PST'
2: In as.POSIXct.POSIXlt(as.POSIXlt(x, tz, ...), tz, ...) :
  unknown timezone 'PST'
3: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'PST'
But I don't see the same problem when using `tz =
"America/Los_Angeles"` or `tz = "PST8PDT"`.


print(lubridate::parse_date_time("1970-01-01 00:01:00",          "ymd
HMS"          , tz = "PST8PDT"))
print(as.POSIXct                ("1970-01-01 00:01:00", format =
"%Y-%m-%d %H:%M:%S", tz = "PST8PDT"))


outputs:
[1] "1970-01-01 00:01:00 PST"
[1] "1970-01-01 00:01:00 PST"
I would hesitate to use `tz = Sys.timezone()` because someone from
another province/state might not be able to use your code. Depends on
whether this work is being shared with other people though, up to you.

On Tue, Mar 1, 2022 at 8:51 PM Boylan, Ross via R-help
<r-help at r-project.org> wrote:
Message-ID: <CAPcHnpTELPUMZ8FB9O86VwJWwc5=d+ERS=ct2YXvxfnfFG_=mw@mail.gmail.com>
In-Reply-To: <BY3PR05MB811676D913B9117776364CDE87039@BY3PR05MB8116.namprd05.prod.outlook.com>