I am trying to sort through times in a table and I have to work with different time zones so it is a great pain. Essentially, I have this:
dateSort <- function(times, date){
if (hour(times)>=16) {
date = as.Date(date - 1)
table$TimePart <<- as.POSIXct(paste(date, times, sep=" "), tz="America/Chicago")
} else {
table$TimePart <<- as.POSIXct(paste(date, times, sep=" "), tz="America/Chicago")
}
return(table$TimePart)
}
The table$TimePart
date-times are all in "YMD-HMS" format. I'm not sure why this does not work as expected.
I want any date-time that has a time greater than 16:00:00 to become a day earlier.