[Rd] Wishlist: Function 'difftime' to honor 'tzone' attribute (PR#14182)
suharto_anggono at yahoo.com
suharto_anggono at yahoo.com
Tue Jan 12 06:35:12 CET 2010
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"
More information about the R-devel
mailing list