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

no warning (or error) with impossible dates #2

Closed
scottyaz opened this issue Mar 7, 2019 · 4 comments · Fixed by #6
Closed

no warning (or error) with impossible dates #2

scottyaz opened this issue Mar 7, 2019 · 4 comments · Fixed by #6
Assignees
Labels
enhancement New feature or request fixed on github This has been fixed on github, but not yet migrated to CRAN good first issue Good for newcomers

Comments

@scottyaz
Copy link

scottyaz commented Mar 7, 2019

When passing a character as a date to date2week it seems like only the last two numbers (understandably) are read in the presumed day field. Seems like at a minimum a warning should be thrown to indicate that this conversion is assuming that the characters are in Y M D format. If more than two digits are picked up in the month or day position, perhaps an error or warning should also be thrown?

`
R> date2week("1910/12/11",week_start="saturday")

[1] "1910-W50-2"

R> date2week("1910/12/111",week_start="saturday")

[1] "1910-W50-2"

R> date2week("1910/12/1111",week_start="saturday")

[1] "1910-W50-2"
`

@zkamvar zkamvar self-assigned this Mar 7, 2019
@zkamvar zkamvar added enhancement New feature or request good first issue Good for newcomers labels Mar 7, 2019
@zkamvar
Copy link
Member

zkamvar commented Mar 7, 2019

Hi @scottyaz,

Thank you for the issue. You've got a good point! This behavior is due to the fact that the first thing date2week() attempts to do is convert the input to a POSIXlt object:

aweek/R/date2week.R

Lines 97 to 100 in 51b36c9

date2week <- function(x, week_start = 1, floor_day = FALSE, numeric = FALSE, factor = FALSE, ...) {
x <- tryCatch(as.POSIXlt(x, ...), error = function(e) e)

I think it makes sense to throw an error here and assume that users will have already converted their dates to yyyy-mm-dd format (if a character).

@zkamvar
Copy link
Member

zkamvar commented Mar 7, 2019

Hi @scottyaz,

I've fixed this in #4, would you mind checking to see if it works for you?

You can install the proposed change with:

remotes::install_github("reconhub/aweek#4")

@scottyaz
Copy link
Author

scottyaz commented Mar 7, 2019

Works fine though I guess in someways it is a shame to not be borrowing from as.POSIXct()'s attempt to be smart (e.g., its nice that it works with slashes, with mm of only a single number etc).

@zkamvar
Copy link
Member

zkamvar commented Mar 7, 2019

Works fine though I guess in someways it is a shame to not be borrowing from as.POSIXct()'s attempt to be smart (e.g., its nice that it works with slashes, with mm of only a single number etc).

True, but as.POSIXlt() gives you those same impossible dates that caused the issue in the first place:

as.POSIXlt("1910/12/1111")
#> [1] "1910-12-11 GMT"

Created on 2019-03-07 by the reprex package (v0.2.1)

The way I see it, parsing non-standard dates is a bit out of the scope for aweek since there are packages like lubridate and linelist that deal with this very issue.

zkamvar added a commit that referenced this issue Mar 8, 2019
@zkamvar zkamvar added the fixed on github This has been fixed on github, but not yet migrated to CRAN label Mar 8, 2019
@zkamvar zkamvar closed this as completed in #6 Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed on github This has been fixed on github, but not yet migrated to CRAN good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants