Bug 14182 - Wishlist: Function 'difftime' to honor 'tzone' attribute
Wishlist: Function 'difftime' to honor 'tzone' attribute
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: Wishlist
old
ix86 (32-bit) Windows 32-bit
: P5 normal
Assigned To: Jitterbug compatibility account
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-01-12 11:33 UTC by Jitterbug compatibility account
Modified: 2010-03-22 08:33 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2010-01-12 11:33:09 UTC
From: suharto_anggono@yahoo.com
Full_Name: Suharto Anggono
Version: 2.8.1
OS: Windows
Submission from: (NULL) (125.165.84.118)


PR#14076 inspired me to write this.

> t1 <- as.POSIXct("1970-01-01 00:00:00", tz="GMT")
> t2 <- as.POSIXlt("1970-01-01 00:00:00", tz="GMT")
> t1 - t2
Time difference of 7 hours

Above, t1 and t2 represent the same time in the same specified timezone.
Therefore, it is reasonable if their difference is zero.

The result is like above because the function '-.POSIXt' calls the function
'difftime', and function 'difftime' does not honor 'tzone' attribute, as can be
seen from this part of the function definition.

function (time1, time2, tz = "", units = c("auto", "secs", "mins",
    "hours", "days", "weeks"))
{
    time1 <- as.POSIXct(time1, tz = tz)
    time2 <- as.POSIXct(time2, tz = tz)
    ...
}

Function 'difftime' calls 'as.POSIXct' with the value of 'tz' argument. If 'tz'
argument is not supplied, "" (current timezone) is used.

I wish function 'difftime' could honor 'tzone' attribute. The above part of the
function definition can be changed to be like this.

function (time1, time2, tz, units = c("auto", "secs", "mins",
    "hours", "days", "weeks"))
{
    if (missing(tz)) {
        time1 <- as.POSIXct(time1)
        time2 <- as.POSIXct(time2)
    }
    else {
        time1 <- as.POSIXct(time1, tz = tz)
        time2 <- as.POSIXct(time2, tz = tz)
    }
    ...
}

I see that, if 'tz' argument is not supplied, function 'as.POSIXct.POSIXlt' uses
the value of 'tzone' attribute if present.

> version
               _
platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          2
minor          8.1
year           2008
month          12
day            22
svn rev        47281
language       R
version.string R version 2.8.1 (2008-12-22)
> sessionInfo()
R version 2.8.1 (2008-12-22)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MON
ETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United
States.1252


attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
> Sys.timezone()
[1] "ICT"

Comment 1 Jitterbug compatibility account 2010-01-12 21:36:44 UTC
Audit (from Jitterbug):
Tue Jan 12 15:36:44 2010	ripley	moved from incoming to wishlist
Comment 2 Brian Ripley 2010-03-22 08:33:54 UTC
Changed for 2.12.0 (that is, tested and will go into R-devel next week)