Bug 16621 - strptime(, tz=x) returns inconsistent gmtoff and tzone properties
Summary: strptime(, tz=x) returns inconsistent gmtoff and tzone properties
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Accuracy (show other bugs)
Version: R 3.2.2
Hardware: x86_64/x64/amd64 (64-bit) Linux
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-12-04 12:49 UTC by Alex Bertram
Modified: 2015-12-04 12:49 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 Alex Bertram 2015-12-04 12:49:25 UTC
When the format provided to strptime() includes an offset (%z) element _AND_ the tz argument, the resulting POSIXlt value has a gmtoff that conflicts with the tzone attribute.

For example:

> t <- strptime('24/Aug/2014:17:57:26 +0200', '%d/%b/%Y:%H:%M:%S %z', 
+                tz = 'Pacific/Honolulu')

> t
[1] "2014-08-24 05:57:26"

> str(unclass(t))
List of 11
 $ sec   : num 26
 $ min   : int 57
 $ hour  : int 5
 $ mday  : int 24
 $ mon   : int 7
 $ year  : int 114
 $ wday  : int 0
 $ yday  : int 235
 $ isdst : int 0
 $ zone  : chr ""
 $ gmtoff: int 7200
 - attr(*, "tzone")= chr [1:3] "Pacific/Honolulu" "HST" "HDT"

The time fields seem to be correct, at 17:57 in the GMT+2 time zone: it's indeed 5:57 in Hawaii, but the gmt offset 7200 refers to the GMT+2 timezone, not Hawaii, whose offset is -10 hours, or -36000 seconds.

Do I misunderstand the purpose of the gmtoff value or is something that should be fixed? If so, will happily submit patch.

> str(R.Version())
List of 14
 $ platform      : chr "x86_64-pc-linux-gnu"
 $ arch          : chr "x86_64"
 $ os            : chr "linux-gnu"
 $ system        : chr "x86_64, linux-gnu"
 $ status        : chr ""
 $ major         : chr "3"
 $ minor         : chr "2.0"
 $ year          : chr "2015"
 $ month         : chr "04"
 $ day           : chr "16"
 $ svn rev       : chr "68180"
 $ language      : chr "R"
 $ version.string: chr "R version 3.2.0 (2015-04-16)"
 $ nickname      : chr "Full of Ingredients"