I have a series of dates stored in class = c("POSIXct", "POSIXt"). Some of these dates cross the UK clock changes, resulting in different timezones for consecutive days, which causes problems when calculating days between dates e.g. the clock change on 29/3/2015 shifts timezone from GMT to BST
"2015-03-29 GMT" "2015-03-30 BST"
Can I force all of my dates into the same timezone without messing up the dates?
I've tried using as.Date(), which works fine when all dates are in the same timezone, but it causes problems when dates cross the clock change.
Here is a reproducible example (possibly only in the UK?):
df2 <- as.data.frame(
structure(
list(DateOfEntry = structure(c(1426809600, 1426896000,
1426982400, 1427068800,
1427155200, 1427241600,
1427328000, 1427414400,
1427500800, 1427587200,
1427670000, 1427756400),
class = c("POSIXct", "POSIXt"),
tzone = "", label = "Date of entry")),
class = "data.frame", .Names = c("DateOfEntry"),
row.names = c(NA, -12L)))
df2$new_date <- as.Date(df2$DateOfEntry)
This results in this output for me (in the UK with clock change on 29/3/2015):
DateOfEntry new_date
2015-03-20 2015-03-20
2015-03-21 2015-03-21
2015-03-22 2015-03-22
2015-03-23 2015-03-23
2015-03-24 2015-03-24
2015-03-25 2015-03-25
2015-03-26 2015-03-26
2015-03-27 2015-03-27
2015-03-28 2015-03-28
2015-03-29 2015-03-29
2015-03-30 2015-03-29
2015-03-31 2015-03-30
Note the repetition of 29/3/2015 and the 1 day difference between DateofEntry==2015-03-30
& new_date==2015-03-29