2

I am trying to convert a unix epoch timestamps to a date-time object using as.POSIXct()

I need to specify timezones (either Europe/London or UTC) when I call as.POSIXct().

If I run

> t<-as.POSIXct(1445329330, tz="Europe/London", origin="1970-01-01")
> t

R returns "2015-10-20 09:22:10 BST" Warning messages: 1: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'default/Europe/London' 2: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'default/Europe/London'

I have tried specifying tz="BST", but this also returns warnings

Warning messages:
1: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'BST
          '
2: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'default/Europe/London'
3: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'BST
          '
4: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'default/Europe/London'

I have looked up the zoneinfo/zone.tab as per Joshua Ulrich's post and "Europe/London" does appear in the zone.tab file, while "BST" does not. So I think that Europe/London should be a valid tz option. Is this correct?

Does anyone have suggestions as to why I am getting warnings, and why the specified timezone is not being assigned to the as.POSIXct object?

It should be noted that my scripts which call as.POSIXct() were running without warnings prior to updating MacOS to High Sierra. Could the OS update lead to these warnings? When I run Sys.timezone() it returns NA

Many thanks in advance

Iris

IrisOren
  • 69
  • 1
  • 1
  • 6
  • Weird, I don't receive any warning message when I run your command. I'm using R 3.4.1. – thc Nov 15 '17 at 17:53
  • R-3.3.1, no warning. – r2evans Nov 15 '17 at 18:10
  • R-3.4.2 If I try to change the timezone to "BST" I get the same warnings. I also get the same warning when I change the timezone to "mytime'. If I use anything else on [this list that the tz is based on](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) I don't have a problem, even if they are deprecated. I am thinking that BST just isn't an option? I am using `Sys.setenv(TZ='MST')` to set the tz. – leerssej Nov 15 '17 at 18:20
  • I am using R-3.2.0 - reluctant to upgrade until I have finished current project – IrisOren Nov 15 '17 at 19:33
  • I am running MacOS High Sierra and had this problem with R-3.4.2 but no problem after upgrading to R-3.4.3 – C8H10N4O2 Feb 02 '18 at 16:22

3 Answers3

9

I am having a similar issue on macOS High Sierra 10.13.1. As soon as, I try to do anything with dates, I get the following error.

> as.POSIXct("2017-10-01", format = "%Y-%m-%d")
[1] "2017-10-01 GMT"
Warning message:
In strptime(x, format, tz = tz) :
  unknown timezone 'zone/tz/2017c.1.0/zoneinfo/Pacific/Auckland'

The warning goes away if I set the environment variable to my timezone and I get the date back with the correct timezone.

> Sys.setenv(TZ = "Pacific/Auckland")
> as.POSIXct("2017-10-01")
[1] "2017-10-01 NZDT"

So, I have been setting the environment variable every time I need to do something to do with dates.

However, I have found this link talking about the same thing. Peter Dalgaard from R Core Team has replied saying this was a bug in macOS 10.13 Beta and that it is up to Apple to sort it out.

I am thinking to put Sys.setenv(TZ = "Pacific/Auckland") into .Rprofile so that it sets the time zone every time I start RStudio. I hope this helps.

Here is a link that might be useful if you want to try the .Rprofile approach I mentioned.

Update: It seems like this has been resolved in R 3.4.3. You can read more about it in the R news. Below is the related part of the release notes.

INSTALLATION on a UNIX-ALIKE

A workaround has been added for the changes in location of time-zone files in macOS 10.13 'High Sierra' and again in 10.13.1, so the default time zone is deduced correctly from the system setting when R is configured with --with-internal-tzcode (the default on macOS).

I can confirm that the new version of R resolves the issues with date/time objects.

> Sys.timezone()
[1] "Pacific/Auckland"
> Sys.time()
[1] "2017-12-30 16:22:32 NZDT"
2

It does look like you need to update your system with a timezone, even though it isn't being used.

I can't seem to set my timezone to NA, but if I set my environment with, for example Sys.setenv(TZ='Twilight Zone'), or anything that isn't on the tz list I also get the same errors that you do.

leerssej
  • 14,260
  • 6
  • 48
  • 57
  • 3
    Thanks! I set the Sys.setenv(TZ="Europe/London") and all warnings have disappeared. – IrisOren Nov 15 '17 at 19:32
  • Although it is still coercing the "Europe/London" in the as.POSIXct call to "BST" in the assigned object – IrisOren Nov 15 '17 at 19:39
  • It does that for me too. It appears that the savings time switch is being handled internally, and that we can't force a time zone to be just one of its phases. If you drop in a timepoint from after daylight savings time changes back you will get the timezone listed as GMT. For example: `t<-as.POSIXct(1445929330, tz="Europe/London", origin="1970-01-01")` – leerssej Nov 15 '17 at 19:50
0

Looking at the output it is not actually giving a warning about 'Europe/London', just about other variations ('BST' and 'default/Europe/London').

Could it be that it are errors of previous commands still lingering? Do you get the same if run you the as.POSIXct(1445329330, tz="Europe/London", origin="1970-01-01") again, or even restart R?

I still get the error about BST even if using the correct timezone

> as.POSIXct(1445329330, tz="BST", origin="1970-01-01")
[1] "2015-10-20 08:22:10 GMT"
Warning message:
In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'BST'
> as.POSIXct(1445329330, tz="Europe/London", origin="1970-01-01")
[1] "2015-10-20 09:22:10 BST"
Warning message:
In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'BST'
Rutger
  • 76
  • 4