Hi Devs,

In my UTC+1 timezone the following code returns TRUE

     t <- as.POSIXct("1999-12-31 23:50:00", tz = "UTC")
     t > "2000-01-01"
     ## TRUE

For a person in US it would return FALSE.

The reason for this is that timezone of the "t" object is ignored in
base:::Ops.POSIXt.

Could this please be fixed? I am attaching a simple patch in case there is
interest.

Thanks,

 Vitalie



--- a/src/library/base/R/datetime.R
+++ b/src/library/base/R/datetime.R
@@ -290,8 +290,14 @@ Ops.POSIXt <- function(e1, e2)
     if (!boolean)
         stop(gettextf("'%s' not defined for \"POSIXt\" objects", .Generic),
              domain = NA)
-    if(inherits(e1, "POSIXlt") || is.character(e1)) e1 <- as.POSIXct(e1)
-    if(inherits(e2, "POSIXlt") || is.character(e2)) e2 <- as.POSIXct(e2)
+    tzone <- function(obj){
+        tz <- attr(obj, "tzone")
+        if(is.null(tz)) "" else tz[1L]
+    }
+    if(is.character(e1)) e1 <- as.POSIXct(e1, tz = tzone(e2))
+    else if(inherits(e1, "POSIXlt")) e1 <- as.POSIXct(e1)
+    if(is.character(e2)) e2 <- as.POSIXct(e2, tz = tzone(e1))
+    else if(inherits(e2, "POSIXlt")) e2 <- as.POSIXct(e2)
     check_tzones(e1, e2)
     NextMethod(.Generic)
 }
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to