-
Notifications
You must be signed in to change notification settings - Fork 12
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
Incorrect conditions in .validate_dates (internal functions) #46
Comments
Can you make an example please? |
fixes incorrect conditions when checking dates for `present`
I think that @Nblws is correct here, @kauedesousa. See my reprex below. If the very first available date and very last available dates are selected then you end up with invalid dates. availability = c("1981-01-01", "0")
x = c("1981-01-01", format(Sys.Date() - 45, "%Y-%m-%d"))
xmin <- as.Date(x[1], format = "%Y-%m-%d")
xmax <- as.Date(x[2], format = "%Y-%m-%d")
# the first day from which the dataset is available
past <- as.Date(availability[1], origin = "1970-01-01")
# the most recent date from which the dataset is available
present <- availability[2]
# generally it takes 45 days to update
if (present == "0") {
present <- Sys.Date() - 45
present <- format(present, "%Y-%m-%d")
}
# last given date should be higher than first
cond1 <- as.integer(xmax - xmin) > 1
# no older than past date
cond2 <- xmin > past
# no later then present date
cond3 <- xmax < present
cond1
#> [1] TRUE
cond2
#> [1] FALSE
cond3
#> [1] FALSE Created on 2023-01-21 with reprex v2.0.2 If you change as suggested you end up passing. availability = c("1981-01-01", "0")
x = c("1981-01-01", format(Sys.Date() - 45, "%Y-%m-%d"))
xmin <- as.Date(x[1], format = "%Y-%m-%d")
xmax <- as.Date(x[2], format = "%Y-%m-%d")
# the first day from which the dataset is available
past <- as.Date(availability[1], origin = "1970-01-01")
# the most recent date from which the dataset is available
present <- availability[2]
# generally it takes 45 days to update
if (present == "0") {
present <- Sys.Date() - 45
present <- format(present, "%Y-%m-%d")
}
# last given date should be higher than first
cond1 <- as.integer(xmax - xmin) > 1
# no older than past date
cond2 <- xmin >= past
# no later then present date
cond3 <- xmax <= present
cond1
#> [1] TRUE
cond2
#> [1] TRUE
cond3
#> [1] TRUE Created on 2023-01-21 with reprex v2.0.2 Looking at the |
At the moment it is not possible to get values from first and last dates as conditions in .validate_dates are strict :
At least for the condition on past date, I believe this should be greater or equal.
Best,
Victor
The text was updated successfully, but these errors were encountered: