If I set TZ in the environment to something reasonable (I've used TZ=EST+5
and TZ="EST+5EDT,M4.1.0/2,M10.5.0/2"), R gives correct answers for the
current time, and returns a reasonable timezone string for Sys.time():
D:\home\setzer>set TZ=EST+5EDT,M4.1.0/2,M10.5.0/2
D:\home\setzer>echo %TZ%
EST+5EDT,M4.1.0/2,M10.5.0/2
D:\home\setzer>Rterm
R : Copyright 2001, The R Development Core Team
Version 1.2.1 (2001-01-15)
[...]
[Previously saved workspace restored]
date()
[1] "Mon Jan 22 17:46:11 2001"
Sys.time()
[1] "2001-01-22 17:46:16 EST"
Sys.timezone()
[1] "EST+5EDT,M4.1.0/2,M10.5.0/2"
q("no")
D:\home\setzer>time
Current time is 5:47:15.76p
If I unset TZ, then the timezone reported in R doesn't make sense, really.
D:\home\setzer>set TZ=
D:\home\setzer>echo %TZ%
ECHO is on
D:\home\setzer>Rterm
[...]
Sys.time()
[1] "2001-01-22 22:49:49 Eas"
Sys.timezone()
[1] "Eastern Daylight Time"
So now the time returned is UTC. When I was experimenting with setting the
timezone, I inadvertantly included double quotes in the TZ string. When I
asked for Sys.time(), the timezone part of the resulting string was \"Ea,
so the string being reported is just being copied unconditionally into the
output string.
I've found the warning in the documentation for as.POSIXct to try setting
TZ on UNIX-like systems if the POSIX functions give unusual results;
perhaps this should apply to Windows systems, too? That doesn't explain
the return of date() which relies on the OS to set the time zone (and, when
I execute the same code as a stand-alone program, I get the correct system
time). It is as if some startup code looks for TZ in the environment, and
if it is not there, sets it to a value which, perhaps, the system does not
recognize as valid, and defaults to GMT.
This is what I get inside Rgui when I query the TZ variable (I have not set
it in the environment):
Sys.getenv("TZ")
TZ
"Eastern Daylight Time"
It seems to me that, if this is going to be used to set the time zone for
POSIX functions, it should look like one of the standard ways of specifying
a time zone (all I know about this is what I read in the libc manual about
the POSIX date-time functions, so I may be way off base here for the
Windows implementation).
R. Woodrow Setzer, Jr. Phone:
(919) 541-0128
Experimental Toxicology Division Fax: (919) 541-5394
Pharmacokinetics Branch
NHEERL MD-74; US EPA; RTP, NC 27711
Woodrow
Setzer/RTP/USEPA/US@ To: r-help at lists.R-project.org
EPA cc:
Sent by: Subject: [R] system time is 5 hours off in Windows
owner-r-help at stat.ma
th.ethz.ch
01/19/2001 04:49 PM
Am I missing a configuration step? The value returned by date() and
Sys.time() is five hours later than the system time. Furthermore,
Sys.timezone() returns Eastern Daylight Time, whereas we are really
currently in Eastern Standard Time. I am running:
_
platform i386-pc-mingw32
arch x86
os Win32
system x86, Win32
status
major 1
minor 2.1
year 2001
month 01
day 15
language R
R. Woodrow Setzer, Jr. Phone:
(919) 541-0128
Experimental Toxicology Division Fax: (919) 541-5394
Pharmacokinetics Branch
NHEERL MD-74; US EPA; RTP, NC 27711
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 22 Jan 2001 Setzer.Woodrow at epamail.epa.gov wrote:
[...]
I've found the warning in the documentation for as.POSIXct to try setting
TZ on UNIX-like systems if the POSIX functions give unusual results;
perhaps this should apply to Windows systems, too? That doesn't explain
It seems OK everywhere else, whic is why it is not mentioned there.
the return of date() which relies on the OS to set the time zone (and, when
I execute the same code as a stand-alone program, I get the correct system
time). It is as if some startup code looks for TZ in the environment, and
if it is not there, sets it to a value which, perhaps, the system does not
recognize as valid, and defaults to GMT.
Windows code does not use TZ according to its documentation.
This is what I get inside Rgui when I query the TZ variable (I have not set
it in the environment):
Sys.getenv("TZ")
TZ
"Eastern Daylight Time"
R sets it for its own purposes.
It seems to me that, if this is going to be used to set the time zone for
POSIX functions, it should look like one of the standard ways of specifying
a time zone (all I know about this is what I read in the libc manual about
the POSIX date-time functions, so I may be way off base here for the
Windows implementation).
Right. It is not documented and does not in general work for Windows.
We do it by hand on Windows. It is possible that what we do (using
tzname and tzset()) is upsetting date(), which I have no idea how it works,
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
As discussed in another thread, the date() function returns the
current date and time (possibly in the wrong time zone on Windows).
What I'm interested in getting is a value that I can do calculations
with, to support animations. That is, I'd like to get the current
time, do a display, do some calculations, then get the current time
again and calculate the update to the display based on the time
difference.
Do I have to write my own external function, or is this already
available somewhere? (I could parse date(), but that will only give
me 1 second resolution; I think the system clock will do better on
most systems.)
(I know about system.time(), but I don't think it's quite appropriate:
I don't just want to know how long the first display calculation took,
I need to know the time at the start of the next one. I'm worried
that there will be slippage if I use system.time().)
Duncan Murdoch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
As discussed in another thread, the date() function returns the
current date and time (possibly in the wrong time zone on Windows).
What I'm interested in getting is a value that I can do calculations
with, to support animations. That is, I'd like to get the current
time, do a display, do some calculations, then get the current time
again and calculate the update to the display based on the time
difference.
Do I have to write my own external function, or is this already
available somewhere? (I could parse date(), but that will only give
me 1 second resolution; I think the system clock will do better on
most systems.)
(I know about system.time(), but I don't think it's quite appropriate:
I don't just want to know how long the first display calculation took,
I need to know the time at the start of the next one. I'm worried
that there will be slippage if I use system.time().)
Just to complete the discussion on date parsing,
unclass(as.POSIXct(strptime(date(),"%c")))
or
as.POSIXct(strptime(date(),"%c")) - structure(0,class="POSIXct")
gives the time in seconds since the beginning of time() (generally Jan
1 1970 0:00:00 GMT on Unixen).
However, I think proc.time()[3] is more relevant for your needs.
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._