tidyverts / tsibble

Tidy Temporal Data Frames and Tools
https://tsibble.tidyverts.org
GNU General Public License v3.0
527 stars 49 forks source link

`yearweek()` sometimes returns innacurate results #297

Closed DOH-RPS1303 closed 1 year ago

DOH-RPS1303 commented 1 year ago

As an example:

ymd("2022-01-02") %>% yearweek()
<yearweek[1]>
[1] "2021 W52"
# Week starts on: Monday

Manually setting the time zone doesn't appear to help:

> test_date <- ymd("2022-01-02", tz = "America/Los_Angeles")
> yearweek(test_date)
<yearweek[1]>
[1] "2021 W52"
# Week starts on: Monday
> test_date <- ymd("2022-01-02", tz = "UTC")
> yearweek(test_date)
<yearweek[1]>
[1] "2021 W52"
# Week starts on: Monday

Here's the package versions and system information:

# R.version
               _                                
platform       x86_64-w64-mingw32               
arch           x86_64                           
os             mingw32                          
crt            ucrt                             
system         x86_64, mingw32                  
status                                          
major          4                                
minor          2.2                              
year           2022                             
month          10                               
day            31                               
svn rev        83211                            
language       R                                
version.string R version 4.2.2 (2022-10-31 ucrt)
nickname       Innocent and Trusting  

# package versions
> packageVersion("lubridate")
[1] ‘1.9.0’
> packageVersion("tsibble")
[1] ‘1.1.3’

# system timezone
> Sys.timezone()
[1] "America/Los_Angeles"
mitchelloharawild commented 1 year ago

This is the correct week if the week starts on Monday. The last week of 2022 starts on Monday 27th of December and ends on Sunday 2nd of January.