[R-pkg-devel] Surprised by as.Date() and lubridate::today()

Pedro J. Aphalo pedro.aphalo at helsinki.fi
Mon Jun 19 23:44:39 CEST 2017


I was surprised first by the behaviour of lubridate::today(), and when I 
investigated further, by the behaviour of as.Date.POSIXlt(). Some 
examples follow:

# today() does not behave as I expected
tz(now(tzone = "EET"))
tz(today(tzone = "EET")) # UTC!!
today("America/New_York") == today("Asia/Tokyo") # FALSE with no warning 
(lack of warning is wrong?).
tz(today("America/New_York")) # UTC!
tz(today("Asia/Tokyo")) # UTC!
ymd("2017-06-19", tz = "America/New_York") == ymd("2017-06-20", tz = 
"Asia/Tokyo") # FALSE with warning.
tz(ymd("2017-06-19", tz = "America/New_York")) # OK
tz(ymd("2017-06-20", tz = "Asia/Tokyo")) # OK

# nothing unusual here
tz(as.POSIXlt(now(), tz = "EET"))
tz(as.POSIXlt(now(tzone = "EET")))
tz(as.POSIXlt(now(tzone = "EET"), tz = "EET"))
# but the unexpected seems to be the behaviour of as.Date.POSIXlt() as 
all returned values have tz set to "UTC"
tz(as.Date(as.POSIXlt(now())))  # UTC!!
tz(as.Date(as.POSIXlt(now(tzone = "EET"), tz = "EET"), tz = "EET"))  # UTC!!
tz(as.Date(as.POSIXlt(now(), tz = "EET"), tz = "EET"))  # UTC!!
tz(as.Date(as.POSIXlt(now()), tz = "EET"))  # UTC!!

Is this as expected? (R 3.4.0 Windows 10 64, and R 3.3.3, with lubridate 

Thanks in advance for any insight.

Best regards,


Pedro J. Aphalo
University Lecturer, Principal Investigator
(Office 4417, Biocenter 3, Viikinkaari 1)

Department of Biosciences
Plant Biology
P.O. Box 65
00014 University of Helsinki

e-mail: pedro.aphalo at helsinki.fi <mailto:pedro.aphalo at helsinki.fi>
Tel. (mobile) +358 50 4150623
Tel. (office) +358 2941 57897

*Web sites and blogs*
Web site (research group): http://blogs.helsinki.fi/senpep-blog/
Web site (own teaching): http://www.helsinki.fi/people/pedro.aphalo/
Web site (using R in photobiology): http://www.r4photobiology.info/
UV4Plants <http://www.uv4plants.org/> (communications officer), ESP 
<http://www.photobiology.eu/> (member) SEB <http://www.sebiology.org/> 
(member), BES <http://www.britishecologicalsociety.org/> (member), SPPS 
<http://www.spps.fi/> (member), SMS 
<http://www.metsatieteellinenseura.fi/english> (member), TUG 
<http://tug.org/> (member), FOAS <http://www.foastat.org/> (member).

	[[alternative HTML version deleted]]

More information about the R-package-devel mailing list