Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse_datetime uses UTC instead of system default when locale(tz="") #1185

Closed
pgramme opened this issue Mar 26, 2021 · 1 comment
Closed
Labels
bug an unexpected problem or unintended behavior datetime 📆 Windows 🪟

Comments

@pgramme
Copy link

pgramme commented Mar 26, 2021

Dear readr ;-)

The documentation of locale(...) says that system default timezone should be used when tz="". But on Windows, with CET as system timezone, this is not what I observe: it seems UTC is used instead.

See the last row in the following reprex: the timezone of the datetime is correctly set to "", but its value shows that it was interpreted as UTC and displayed as CET.

Am I interpreting the doc incorrectly or is it a bug?

Thanks!
Pierre

library(readr)

version
#>                _                           
#> platform       x86_64-w64-mingw32          
#> arch           x86_64                      
#> os             mingw32                     
#> system         x86_64, mingw32             
#> status                                     
#> major          4                           
#> minor          0.2                         
#> year           2020                        
#> month          06                          
#> day            22                          
#> svn rev        78730                       
#> language       R                           
#> version.string R version 4.0.2 (2020-06-22)
#> nickname       Taking Off Again
packageVersion("readr")
#> [1] '1.4.0'

check_tz = function(tz) {
  l = locale(tz = tz)
  tibble::tibble(
    tz0=tz, 
    s0 = "2021-01-01 09:00", 
    dt0 = parse_datetime(s0, locale = l), 
    tz1 = lubridate::tz(dt0),
    s1 = output_column(dt0)
  )
}

Sys.timezone()
#> [1] "Europe/Paris"
check_tz("UTC")
#> # A tibble: 1 x 5
#>   tz0   s0               dt0                 tz1   s1                  
#>   <chr> <chr>            <dttm>              <chr> <chr>               
#> 1 UTC   2021-01-01 09:00 2021-01-01 09:00:00 UTC   2021-01-01T09:00:00Z
check_tz("CET")
#> # A tibble: 1 x 5
#>   tz0   s0               dt0                 tz1   s1                  
#>   <chr> <chr>            <dttm>              <chr> <chr>               
#> 1 CET   2021-01-01 09:00 2021-01-01 09:00:00 CET   2021-01-01T08:00:00Z
check_tz("")
#> # A tibble: 1 x 5
#>   tz0   s0               dt0                 tz1   s1                  
#>   <chr> <chr>            <dttm>              <chr> <chr>               
#> 1 ""    2021-01-01 09:00 2021-01-01 10:00:00 ""    2021-01-01T09:00:00Z

# Problem with the line above: datetime parsed as in UTC and displayed in the system tz

Created on 2021-03-26 by the reprex package (v0.3.0)

@jimhester jimhester added the bug an unexpected problem or unintended behavior label May 11, 2021
@hadley
Copy link
Member

hadley commented Jul 31, 2023

This all looks ok to me now:

library(readr)

check_tz <- function(tz) {
  parse_datetime("2021-01-01 09:00", locale = locale(tz = tz))
}

check_tz("UTC")
#> [1] "2021-01-01 09:00:00 UTC"
check_tz("CET")
#> [1] "2021-01-01 09:00:00 CET"

check_tz("")
#> [1] "2021-01-01 09:00:00 CST"
check_tz(Sys.timezone())
#> [1] "2021-01-01 09:00:00 CST"

Created on 2023-07-31 with reprex v2.0.2

@hadley hadley closed this as completed Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior datetime 📆 Windows 🪟
Projects
None yet
Development

No branches or pull requests

4 participants