Bug 16503 - strptime produces an error with GMT timezone
Summary: strptime produces an error with GMT timezone
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.2.1
Hardware: x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-08-10 18:34 UTC by Dmitriy Shashkin
Modified: 2015-12-14 13:45 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitriy Shashkin 2015-08-10 18:34:52 UTC
as.Date.character calls strptime function with "GMT" timezone, this call produces a warning. I can reproduce it by calling strptime directly:


.Internal(strptime("2015-01-01", "%Y-%m-%d", "GMT"))

Warning message:
unknown timezone 'localtime'
Comment 1 Dmitriy Shashkin 2015-08-11 09:28:22 UTC
I must clarify. I'm only having this problem with GMT timezone

Restarting R session...
> Sys.getenv("TZ")
[1] "America/Los_angeles"
> .Internal(strptime("2015-08-04", "%Y-%m-%d", "America/Los_Angeles"))
[1] "2015-08-04 PDT"
> .Internal(strptime("2015-08-04", "%Y-%m-%d", "GMT"))
[1] "2015-08-04 GMT"
Warning messages:
1: unable to identify current timezone 'R':
please set environment variable 'TZ' 
2: unknown timezone 'localtime' 
> .Internal(strptime("2015-08-04", "%Y-%m-%d", "GMT"))
[1] "2015-08-04 GMT"
Warning message:
unknown timezone 'localtime' 

So R complaints about TZ variable even though it's actually set. And it only does that when I specify "GMT" timezone. I would gladly avoid using it, but as I mentioned earlier as.Date.character function as well as many others uses "GMT" timezone internally, which leads to the warning message.
Comment 2 Dmitriy Shashkin 2015-08-11 12:34:39 UTC
I've searched the sources by the error message "unable to identify current timezone", found the only occurrence in reg2Olson function. From what I could figure out, at some point it tries to find the current time zone in the windows registry.

I've checked the value stored at the specified registry key on my machine (SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation) and it equals to "Kaliningrad Standard Time".

Later in the code the reg2Olson looks for the TZ from the registry in TZtable list. And apparently there is no entry corresponding to the "Kaliningrad Standard Time". So it makes me think that the problem might not reproduce with less exotic TZ in the registry.

Still it's unclear why doesn't it use the GMT timezone. I've read somewhere that R uses time zone files stored in \share\zoneinfo directory. My "C:\Program Files\R\R-3.2.1\share\zoneinfo" directory has a "GMT" file.

I hope that the this additional information will help.
Comment 3 Brian Ripley 2015-08-12 06:40:16 UTC
Your timezone is not one known to Unicode at the time that function was prepared.

See ?Sys.timezone, which on your system says

  An attempt is made (once only per session) to map Windows' idea of the
  current time zone to a location, following an earlier version of
  \url{http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml}
  It can be overridden by setting the \env{TZ} environment variable
  before any date-times are used in the session.

Did you do that?

I will add Kaliningrad Standard Time to the table, for 3.2.2 patched.
Comment 4 Dmitriy Shashkin 2015-08-12 09:13:18 UTC
Yes, I did set the environment variable 'TZ'. Besides I'm specifying TZ explicitly during the function call. See the snippet below:


> Sys.getenv("TZ")
[1] "America/Los_angeles"
> .Internal(strptime("2015-08-04", "%Y-%m-%d", "GMT"))
[1] "2015-08-04 GMT"
Warning messages:
1: unable to identify current timezone 'R':
please set environment variable 'TZ' 
2: unknown timezone 'localtime'
Comment 5 Brian Ripley 2015-08-12 09:44:17 UTC
Try setting TZ before starting R.

This ought to be resolved in R-devel as from r69003 (as so binary builds will be available soon, probably tomorrow).  It will be ported to R-patched once R 3.2.2 is released, hence will probably get to snapshots of that by next Monday.
Comment 6 Dmitriy Shashkin 2015-08-12 13:19:03 UTC
I've already tried that. I'm setting the environment variable 'TZ' through Renviron.site file.

strptime("2015-08-04", "%Y-%m-%d") works fine, while strptime("2015-08-04", "%Y-%m-%d", "GMT") produces a warning.

OK, I'll check the new version next week and let you know about the results. Thank you!
Comment 7 Brian Ripley 2015-08-12 20:17:57 UTC
I was able to reproduce this in R 3.2.2 RC on my Windows 7 box, and current R-devel works.  It also worked there to set TZ before running R if the Windows' timezone was not on the current known list.
Comment 8 Dmitriy Shashkin 2015-08-13 08:52:11 UTC
I've tried both 3.2.2 RC and 3.2.3 RC and everything works like charm! No warning messages, even if TZ environment variable is not set. So I'll just wait for 3.2.2 final release.

Thank you!
Comment 9 Dmitriy Shashkin 2015-08-18 10:15:04 UTC
Correction: it works without warning only in 3.2.3 RC

3.2.2 still has this problem.