Skip to content

Conversation

@BradThymesAtTheElRoyale

The lubridate::as_date() function relies on the user's timezone, which causes some issues with retrieving the week of the month at the beginning or end of a month when getting the time series signature. Switching to lubridate::as_datetime() solves this issue and returns the expected week of the month. Reprex included below.

Sys.setenv(TZ = 'America/Chicago')
stringi::stri_datetime_fields(lubridate::as_date('2022-11-01'))
#>   Year Month Day Hour Minute Second Millisecond WeekOfYear WeekOfMonth
#> 1 2022    10  31   19      0      0           0         45           6
#>   DayOfYear DayOfWeek Hour12 AmPm Era
#> 1       304         2      7    2   2
stringi::stri_datetime_fields(lubridate::as_datetime('2022-11-01'))
#>   Year Month Day Hour Minute Second Millisecond WeekOfYear WeekOfMonth
#> 1 2022    11   1    0      0      0           0         45           1
#>   DayOfYear DayOfWeek Hour12 AmPm Era
#> 1       305         3      0    1   2

Created on 2023-05-10 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant