I have the following problem: the date column in the data I receive contains dates that do not exist due to daylight saving time. (For example, 2015-03-29 02:00 does not exist in Central European time, because the hours are set directly from 01:59 to 03:00, because the DST takes effect on this day)
Is there a simple and reliable way to determine if a date is valid for daylight saving time?
This is not trivial due to the properties of datetime classes.
# generating the invalid time as POSIXlt object test <- strptime("2015-03-29 02:00", format="%Y-%m-%d %H:%M", tz="CET") # the object seems to represent something at least partially reasonable, notice the missing timezone specification though test # [1] "2015-03-29 02:00:00" # strangely enough this object is regarded as NA by is.na is.na(test) # [1] TRUE # which is no surprise if you consider: is.na.POSIXlt # function (x) # is.na(as.POSIXct(x)) as.POSIXct(test) # [1] NA # inspecting the interior of my POSIXlt object: unlist(test) # sec min hour mday mon year wday yday isdst zone gmtoff # "0" "0" "2" "29" "2" "115" "0" "87" "-1" "" NA
So the easiest way is to check the isdst field of the isdst object, help for POSIXt describes the entry as follows:
isdst
Summer time. Positive, if valid, zero if not, negative if unknown.
Checks isdst field is isdst in the sense that this field is only -1 if the date is invalid due to dst changes or maybe -1 for other reasons?
Version, platform, and locale information
R.version
datetime dst r
snaut
source share