Re: [R] POSIXct time zone and daylight savings issues

2006-10-31 Thread Prof Brian Ripley
On Mon, 30 Oct 2006, Sebastian P. Luque wrote:

 Hi again,

 A related issue I can't quite understand is:


 R tt - as.POSIXct(2006-05-24, tz=EEST)
 R tt
 [1] 2006-05-24 EEST
 R seq(tt, length=12, by=months)
 [1] 2006-05-24 EEST 2006-06-24 EEST 2006-07-24 EEST 2006-08-24 EEST
 [5] 2006-09-24 EEST 2006-10-24 EEST 2006-11-24 EEST 2006-12-24 EEST
 [9] 2007-01-24 EEST 2007-02-24 EEST 2007-03-24 EEST 2007-04-24 EEST
 R tt - as.POSIXct(2006-05-24, tz=EET)
 R seq(tt, length=12, by=months)
 [1] 2006-05-24 EEST 2006-06-24 EEST 2006-07-24 EEST 2006-08-24 EEST
 [5] 2006-09-24 EEST 2006-10-24 EEST 2006-11-24 EET  2006-12-24 EET
 [9] 2007-01-24 EET  2007-02-24 EET  2007-03-24 EET  2007-04-24 EEST
 R sessionInfo()
 R version 2.4.0 (2006-10-03)
 x86_64-pc-linux-gnu

 locale:
 LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C

 attached base packages:
 [1] methods   stats graphics  grDevices utils datasets
 [7] base

 other attached packages:
 lattice
 0.14-9


 i.e. daylight savings 'tzone' attribute gets adjusted automatically when
 providing the standard time attribute, but not when providing the daylight
 savings time.  Does this behaviour depend on the OS/locale?  Should the
 'tz' argument supplied when creating POSIXct objects always be the
 standard time version?

No, it should be a timezone, and the timezone specification includes when 
DST is in effect.  See ?as.POSIXct for details and references of 
timezones.  For example, EST is a timezone without DST and EST5EDT is a 
timezone with DST (and they agree in winter). It looks like Linux is 
interpreting EEST as UTC+3 throughout the year (which appears not to be 
used anywhere as an actual timezone).  So the behaviour is clear: EEST 
does not have DST, and $isdst == 0 in that 'timezone', whereas EET does 
have DST.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] POSIXct time zone and daylight savings issues

2006-10-31 Thread Sebastian P. Luque
On Tue, 31 Oct 2006 09:24:02 + (GMT),
Prof Brian Ripley [EMAIL PROTECTED] wrote:

[...]

 No, it should be a timezone, and the timezone specification includes
 when DST is in effect.  See ?as.POSIXct for details and references of
 timezones.  For example, EST is a timezone without DST and EST5EDT is a
 timezone with DST (and they agree in winter). It looks like Linux is
 interpreting EEST as UTC+3 throughout the year (which appears not to be
 used anywhere as an actual timezone).  So the behaviour is clear: EEST
 does not have DST, and $isdst == 0 in that 'timezone', whereas EET does
 have DST.

Thanks for this explanation.  Very important to check whether the supplied
'tz' is really interpreted as a valid time zone by the OS!


Cheers,

-- 
Seb

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] POSIXct time zone and daylight savings issues

2006-10-30 Thread Sebastian P. Luque
Hi again,

A related issue I can't quite understand is:


R tt - as.POSIXct(2006-05-24, tz=EEST)
R tt
[1] 2006-05-24 EEST
R seq(tt, length=12, by=months)
 [1] 2006-05-24 EEST 2006-06-24 EEST 2006-07-24 EEST 2006-08-24 EEST
 [5] 2006-09-24 EEST 2006-10-24 EEST 2006-11-24 EEST 2006-12-24 EEST
 [9] 2007-01-24 EEST 2007-02-24 EEST 2007-03-24 EEST 2007-04-24 EEST
R tt - as.POSIXct(2006-05-24, tz=EET)
R seq(tt, length=12, by=months)
 [1] 2006-05-24 EEST 2006-06-24 EEST 2006-07-24 EEST 2006-08-24 EEST
 [5] 2006-09-24 EEST 2006-10-24 EEST 2006-11-24 EET  2006-12-24 EET 
 [9] 2007-01-24 EET  2007-02-24 EET  2007-03-24 EET  2007-04-24 EEST
R sessionInfo()
R version 2.4.0 (2006-10-03) 
x86_64-pc-linux-gnu 

locale:
LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] methods   stats graphics  grDevices utils datasets 
[7] base 

other attached packages:
 lattice 
0.14-9 


i.e. daylight savings 'tzone' attribute gets adjusted automatically when
providing the standard time attribute, but not when providing the daylight
savings time.  Does this behaviour depend on the OS/locale?  Should the
'tz' argument supplied when creating POSIXct objects always be the
standard time version?


Cheers,

-- 
Seb

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] POSIXct time zone and daylight savings issues

2006-10-30 Thread Gabor Grothendieck
I don't know the answer to your question but if you are using dates
with no times and don't need time zones (both of which appear to
be the case here) then you could use Date
class and avoid the issue altogether.  See the help desk article in
R News 4/1 where there is a discussion of how to choose the
date time class.

On 10/30/06, Sebastian P. Luque [EMAIL PROTECTED] wrote:
 Hi again,

 A related issue I can't quite understand is:


 R tt - as.POSIXct(2006-05-24, tz=EEST)
 R tt
 [1] 2006-05-24 EEST
 R seq(tt, length=12, by=months)
  [1] 2006-05-24 EEST 2006-06-24 EEST 2006-07-24 EEST 2006-08-24 EEST
  [5] 2006-09-24 EEST 2006-10-24 EEST 2006-11-24 EEST 2006-12-24 EEST
  [9] 2007-01-24 EEST 2007-02-24 EEST 2007-03-24 EEST 2007-04-24 EEST
 R tt - as.POSIXct(2006-05-24, tz=EET)
 R seq(tt, length=12, by=months)
  [1] 2006-05-24 EEST 2006-06-24 EEST 2006-07-24 EEST 2006-08-24 EEST
  [5] 2006-09-24 EEST 2006-10-24 EEST 2006-11-24 EET  2006-12-24 EET
  [9] 2007-01-24 EET  2007-02-24 EET  2007-03-24 EET  2007-04-24 EEST
 R sessionInfo()
 R version 2.4.0 (2006-10-03)
 x86_64-pc-linux-gnu

 locale:
 LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C

 attached base packages:
 [1] methods   stats graphics  grDevices utils datasets
 [7] base

 other attached packages:
  lattice
 0.14-9


 i.e. daylight savings 'tzone' attribute gets adjusted automatically when
 providing the standard time attribute, but not when providing the daylight
 savings time.  Does this behaviour depend on the OS/locale?  Should the
 'tz' argument supplied when creating POSIXct objects always be the
 standard time version?


 Cheers,

 --
 Seb

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] POSIXct time zone and daylight savings issues

2006-10-27 Thread Sebastian P. Luque
Hello,

Suppose we need a function that takes a POSIXct object and need to
calculate the time difference between it and GMT time:


gmtDiff - function(time) {
time.gmt - as.POSIXct(format(time, tz=GMT))
time.plt - as.POSIXlt(time)
dlstime - ifelse(time.plt$isdst  0, 1, 0)
timezone - as.numeric(difftime(time, time.gmt, units=hours))
timezone - dlstime
}


Please note this assumes no daylight savings if the 'isdst' component for
the POSIXlt object is negative (i.e. don't know if DST is in effect).  Now
if we pass some values to this function:


R gmtDiff(as.POSIXct(2006-10-27, tz=GMT))
[1] -5
R gmtDiff(as.POSIXct(Sys.time()))
[1] -6


I would have expected the first call to return zero, but it seems as if
the calculation is always done with respect to the system's locale, and I
can't understand what the function of the 'tzone' attribute is in these
calculations.  ?strptime has information on how to change the locale for
some operations, which in this case didn't change the outcome:


R lct - Sys.getlocale(LC_TIME); Sys.setlocale(LC_TIME, C)
[1] C
R gmtDiff(as.POSIXct(2006-10-27, tz=GMT))
[1] -5
R gmtDiff(as.POSIXct(Sys.time()))
[1] -6
R Sys.setlocale(LC_TIME, lct)
[1] en_CA.UTF-8
R sessionInfo()
R version 2.4.0 (2006-10-03) 
x86_64-pc-linux-gnu 

locale:
LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] methods   stats graphics  grDevices utils datasets 
[7] base 

other attached packages:
  lattice 
 0.14-9 


I'd be grateful for any clarification and advice on how to properly
calculate this time difference.


Cheers,

-- 
Seb

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] POSIXct time zone and daylight savings issues

2006-10-27 Thread Gabor Grothendieck
Try this:

gmtDiff - function(time) time - as.POSIXct(format(time), tz = GMT)

gmtDiff(Sys.time())
gmtDiff(as.POSIXct(2006-10-27, tz = GMT))

which both give me the correct answer currently.

The expression after the minus sign comes from the table at the end
of the help desk article in R News 4/1.  I think you got the parentheses
wrong in your version and I think the isdst calculation needs to
be omitted -- I get the right answer if I leave it out but wrong with it.

On 10/27/06, Sebastian P. Luque [EMAIL PROTECTED] wrote:
 Hello,

 Suppose we need a function that takes a POSIXct object and need to
 calculate the time difference between it and GMT time:


 gmtDiff - function(time) {
time.gmt - as.POSIXct(format(time, tz=GMT))
time.plt - as.POSIXlt(time)
dlstime - ifelse(time.plt$isdst  0, 1, 0)
timezone - as.numeric(difftime(time, time.gmt, units=hours))
timezone - dlstime
 }


 Please note this assumes no daylight savings if the 'isdst' component for
 the POSIXlt object is negative (i.e. don't know if DST is in effect).  Now
 if we pass some values to this function:


 R gmtDiff(as.POSIXct(2006-10-27, tz=GMT))
 [1] -5
 R gmtDiff(as.POSIXct(Sys.time()))
 [1] -6


 I would have expected the first call to return zero, but it seems as if
 the calculation is always done with respect to the system's locale, and I
 can't understand what the function of the 'tzone' attribute is in these
 calculations.  ?strptime has information on how to change the locale for
 some operations, which in this case didn't change the outcome:


 R lct - Sys.getlocale(LC_TIME); Sys.setlocale(LC_TIME, C)
 [1] C
 R gmtDiff(as.POSIXct(2006-10-27, tz=GMT))
 [1] -5
 R gmtDiff(as.POSIXct(Sys.time()))
 [1] -6
 R Sys.setlocale(LC_TIME, lct)
 [1] en_CA.UTF-8
 R sessionInfo()
 R version 2.4.0 (2006-10-03)
 x86_64-pc-linux-gnu

 locale:
 LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=en_CA.UTF-8;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C

 attached base packages:
 [1] methods   stats graphics  grDevices utils datasets
 [7] base

 other attached packages:
  lattice
  0.14-9


 I'd be grateful for any clarification and advice on how to properly
 calculate this time difference.


 Cheers,

 --
 Seb

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] POSIXct time zone and daylight savings issues

2006-10-27 Thread Sebastian P. Luque
On Fri, 27 Oct 2006 14:55:15 -0400,
Gabor Grothendieck [EMAIL PROTECTED] wrote:

 Try this: gmtDiff - function(time) time - as.POSIXct(format(time), tz =
 GMT)

 gmtDiff(Sys.time()) gmtDiff(as.POSIXct(2006-10-27, tz = GMT))

 which both give me the correct answer currently.

 The expression after the minus sign comes from the table at the end of
 the help desk article in R News 4/1.  I think you got the parentheses
 wrong in your version and I think the isdst calculation needs to be
 omitted -- I get the right answer if I leave it out but wrong with it.

Thanks Gabor, this provides the correct result, and the isdst calculation
is no longer needed.


Cheers,

-- 
Seb

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.