At 11:39 AM -0500 11/12/03, Gabor Grothendieck wrote:
You are being hit by a timezone problem. Its not really shifting the days by one. Its working in the GMT timezone, not yours.
If you can accept a date format that chron supports then this is the easiest solution since chron does not support timezones and so can't give you such problems in the first place. For example, the following stays in chron the whole time:
format(datesTest, format="m/day/year") [1] "Oct/01/1952" "Oct/02/1952" "Oct/03/1952"
If you must convert to POSIXt to take advantage of a format only supported by POSIXt then use POSIXlt and specify the timezone explictly:
format(as.POSIXlt(datesTest,tz="GMT"), "%m/%d/%Y") [1] "10/01/1952" "10/02/1952" "10/03/1952"
This solved the problem using as.POSIXlt(). I guess the tz argument doesn't solve the problem using as.POSIXct(). In any case, I'm able to use as.POSIXlt() in my current application.
Its because of subtle problems like this that I think that some sort of naive (i.e. non-timezone) time such as chron or an alternative, should be in the base to encourage wider use.
I agree. Thanks again for your help.
Brian
--- Date: Wed, 12 Nov 2003 10:05:39 -0500 From: Brian Beckage <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Subject: [R] Chron, as.POSIXct problem
Dear R list,
I noticed the following 'problem' when changing the format of dates created with seq.dates() (from the Chron library) using as.POSIXct() (R 1.8.0 on OSX 10.2.8):
[1] 10/01/52 10/02/52 10/03/52datesTest<-seq.dates(from="10/01/1952", length=3, by="days"); datesTest
# Now changing the format to show year as 1952.
[1] "09/30/1952" "10/01/1952" "10/02/1952"datesTest<-format(as.POSIXct(datesTest), "%m/%d/%Y") datesTest
The dates were shifted by one day. The work around is simple enough, e.g.,
datesTest<-format(as.POSIXct(datesTest+1), "%m/%d/%Y")[1] "10/01/1952" "10/02/1952" "10/03/1952"
but I wonder if this is the intended behavior?
Brian
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
_______________________________________________ No banners. No pop-ups. No kidding. Introducing My Way - http://www.myway.com
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help