I had some code that takes in a time and then takes a way a set number of seconds. All works fine apart from an edge case where when you take away the number of seconds you end up at midnight. In the code I am using when this situation occurs, the seconds part of the time disappears. The subsequent code then fails because it is expecting the time in a specific format.
Any ideas how to deal with this situation so the subsequent code doesn't give unexpected results.
Ignore the time zones in the following - I'm just interested in the disappearing seconds.
BaseTime <- "2015-03-25 00:01:00"
adjustment <- 30
GMT1 <- strptime(BaseTime,"%Y-%m-%d %H:%M:%S")
GMTadj <- GMT1 - adjustment
GMTadj
# [1] "2015-03-25 00:00:30 EDT"
GMT <- as.POSIXct(strptime(as.character(GMTadj),"%Y-%m-%d %H:%M:%S"),tz = "GMT") GMT
# [1] "2015-03-25 00:00:30 GMT"
adjustment <- 60
GMT1 <- strptime(BaseTime,"%Y-%m-%d %H:%M:%S")
GMTadj <- GMT1 - adjustment
GMTadj
# [1] "2015-03-25 EDT"
GMT <- as.POSIXct(strptime(as.character(GMTadj),"%Y-%m-%d %H:%M:%S"),tz = "GMT")
GMT
# [1] NA