0

Is this a bug, and if so a known bug? Looks like this question.

times = c('2020-03-28 00:00:00', '2020-03-29 00:00:00', '2020-03-30 00:00:00')

d_utc = as.POSIXct(times, tz='UTC')
d_eur = as.POSIXct(times, tz='Europe/London')
d_nul = as.POSIXct(times)

table(as.Date(d_utc))
#> 
#> 2020-03-28 2020-03-29 2020-03-30 
#>          1          1          1
table(as.Date(d_eur))
#> 
#> 2020-03-28 2020-03-29 
#>          1          2
table(as.Date(d_nul))
#> 
#> 2020-03-28 2020-03-29 
#>          1          2

The tz argument's documentation in ?as.POSIXct states: time zone specification to be used for the conversion, if one is required. System-specific (see time zones), but "" is the current time zone, and "GMT" is UTC (Universal Time, Coordinated). Invalid values are most commonly treated as UTC, on some platforms with a warning.

Looks like default UTC interpretation is not happening.

My environment:

> R.version
               _                           
platform       x86_64-apple-darwin17.0     
arch           x86_64                      
os             darwin17.0                  
system         x86_64, darwin17.0          
status                                     
major          4                           
minor          0.0                         
year           2020                        
month          04                          
day            24                          
svn rev        78286                       
language       R                           
version.string R version 4.0.0 (2020-04-24)
nickname       Arbor Day                   
geotheory
  • 22,624
  • 29
  • 119
  • 196
  • I think this is duplicate of same question you linked. Try `table(as.Date(d_utc, tz='UTC'))`, `table(as.Date(d_eur, tz='Europe/London'))`, and `table(as.Date(d_nul))` – Ronak Shah May 13 '20 at 10:05
  • Thanks. But is it a bug or intended behaviour? If a bug it may have been fixed and reoccured. – geotheory May 13 '20 at 10:08
  • I think this is intended behavior as described in the help page of `?as.Date`. It by default converts POSIXct objects to date in `tz` specified. If you don't specify it, the default is UTC. – Ronak Shah May 13 '20 at 10:14
  • IMO that would be pretty a bizarre 'intended' behaviour! More critically, if your data arrives in POSIXct format I can't see any way to fix it. E.g. `attr(d_nul, "tzone") <- "UTC"; table(as.Date(d_nul))` has no effect. – geotheory May 13 '20 at 10:16

0 Answers0