Converting date strings that range between Mar-14-2010 2:00 and Mar-14-2010 2:59 (inclusive) to date objects (POSIX) returns a NA entity: > strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M") [1] "2010-03-14 02:00:00" This looks fine, however other functions such as plot see a NA object instead: > is.na(strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M")) [1] TRUE I've processed an entire range of dates for 2010 and have only come across this problem for the aforementioned date ranges. For instance, the following dates work fine: > is.na(strptime("3/14/2010 3:00",format="%m/%d/%Y %H:%M")) [1] FALSE > is.na(strptime("10/14/2010 23:00",format="%m/%d/%Y %H:%M")) [1] FALSE which is what I would expect for ALL dates. Could this be a bug with POSIX or strptime? I'm running R x64 2.12.0 on Win7 [[alternative HTML version deleted]]
On Feb 8, 2011, at 10:31 AM, Manuel Gimond wrote:> Converting date strings that range between Mar-14-2010 2:00 and > Mar-14-2010 2:59 (inclusive) to date objects (POSIX) returns a NA > entity: > >> strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M") > [1] "2010-03-14 02:00:00" > > This looks fine, however other functions such as plot see a NA object > instead: > >> is.na(strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M")) > [1] TRUE > > I've processed an entire range of dates for 2010 and have only come > across this problem for the aforementioned date ranges. For instance, > the following dates work fine: > >> is.na(strptime("3/14/2010 3:00",format="%m/%d/%Y %H:%M")) > [1] FALSE > >> is.na(strptime("10/14/2010 23:00",format="%m/%d/%Y %H:%M")) > [1] FALSE > > which is what I would expect for ALL dates. > > Could this be a bug with POSIX or strptime?More likely it has to do with "daylight savings time".> I'm running R x64 2.12.0 on Win7 > > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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.David Winsemius, MD West Hartford, CT
On 2/8/2011 11:47 AM, David Winsemius wrote:> > On Feb 8, 2011, at 10:31 AM, Manuel Gimond wrote: > >> Converting date strings that range between Mar-14-2010 2:00 and >> Mar-14-2010 2:59 (inclusive) to date objects (POSIX) returns a NA >> entity: >> >>> strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M") >> [1] "2010-03-14 02:00:00" >> >> This looks fine, however other functions such as plot see a NA object >> instead: >> >>> is.na(strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M")) >> [1] TRUE >> >> I've processed an entire range of dates for 2010 and have only come >> across this problem for the aforementioned date ranges. For instance, >> the following dates work fine: >> >>> is.na(strptime("3/14/2010 3:00",format="%m/%d/%Y %H:%M")) >> [1] FALSE >> >>> is.na(strptime("10/14/2010 23:00",format="%m/%d/%Y %H:%M")) >> [1] FALSE >> >> which is what I would expect for ALL dates. >> >> Could this be a bug with POSIX or strptime? > > More likely it has to do with "daylight savings time". > >Thanks David, DST was indeed the problem. The data I'm working with is in local standard time. Adding the tz="EST" fixed the problem, e.g.:> is.na(strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M",tz="EST"))[1] FALSE
On Tue, 8 Feb 2011, Manuel Gimond wrote:> Converting date strings that range between Mar-14-2010 2:00 and > Mar-14-2010 2:59 (inclusive) to date objects (POSIX) returns a NA entity: > > > strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M") > [1] "2010-03-14 02:00:00" > > This looks fine, however other functions such as plot see a NA object > instead: > > > is.na(strptime("3/14/2010 2:00",format="%m/%d/%Y %H:%M")) > [1] TRUE > > I've processed an entire range of dates for 2010 and have only come > across this problem for the aforementioned date ranges. For instance, > the following dates work fine: > > > is.na(strptime("3/14/2010 3:00",format="%m/%d/%Y %H:%M")) > [1] FALSE > > > is.na(strptime("10/14/2010 23:00",format="%m/%d/%Y %H:%M")) > [1] FALSE > > which is what I would expect for ALL dates. > > Could this be a bug with POSIX or strptime? I'm running R x64 2.12.0 on Win7You haven't told us your timezone, but very likely you are in one where that hour did not actually exist (as DST came into effect).> [[alternative HTML version deleted]]And you definitely overlooked the request in the posting guide not to send HTML.> > ______________________________________________ > R-help at r-project.org 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. >-- 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 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595