I have created two variables that represent the min and max of yesterday's time:
yesterday_min <- force_tz(as.POSIXct(sprintf('%s 00:00:00', Sys.Date()-1)), 'America/New_York')
yesterday_max <- force_tz(as.POSIXct(sprintf('%s 00:00:00', Sys.Date())), 'America/New_York') - 1L
> yesterday_min
[1] "2018-01-15 EST"
> yesterday_max
[1] "2018-01-15 23:59:59 EST"
> attr(yesterday_min,"tzone")
[1] "America/New_York"
> attr(yesterday_max,"tzone")
[1] "America/New_York"
They are both on the same date, same timezone. However, the function as.Date()
recognizes them as two separate dates. Expected behavior is for both dates to be "2018-01-15"
. Why does this happen and how would one solve this problem?
> as.Date(yesterday_min)
[1] "2018-01-15"
> as.Date(yesterday_max)
[1] "2018-01-16"