Skip to content

Use lubridate::as_datetime in get_timeseries_signature_date function#147

Open
BradThymesAtTheElRoyale wants to merge 1 commit intobusiness-science:masterfrom
BradThymesAtTheElRoyale:master
Open

Use lubridate::as_datetime in get_timeseries_signature_date function#147
BradThymesAtTheElRoyale wants to merge 1 commit intobusiness-science:masterfrom
BradThymesAtTheElRoyale:master

Conversation

@BradThymesAtTheElRoyale
Copy link
Copy Markdown

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