Skip to content

Conversation

@ldecicco-USGS
Copy link
Collaborator

Should now allow this:

start <- "2025-10-01"
> end <- Sys.Date()
> dataRetrieval:::format_api_dates(c(start, end), date = TRUE)
[1] "2025-10-01/2026-02-02"

(which fixes #853 )

and this:

dataRetrieval:::format_api_dates(c("2010-01-01T00:00Z", "2010-01-01T05:00Z"))
[1] "2010-01-01T00:00:00Z/2010-01-01T05:00:00Z"

(which fixes #839 )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be changed to date?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think it should be changed to logical (because it tells the code whether or not to return a date or dateTime)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I meant the input is named "date" and it is logical, right?


if(length(datetime) == 1){
# If the user has "P" or the "/" we assume they know what they are doing
if(grepl("P", datetime, ignore.case = TRUE) |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I tried this with a lowercase "p7d" and "p7D" and the API will not have it. I don't think there's necessarily anything you need to do here, just a random test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can plop a toupper in there, good to know!

Copy link
Collaborator

@ehinman ehinman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Approved. I particularly love this implementation:

start_end <- as.POSIXct(c("2021-01-01 12:15:00",
"2022-01-01 16:45"),
tz = "America/New_York")

dataRetrieval::format_api_dates(start_end)

Very nice.

A couple thoughts/suggestions that are optional: The function documentation for time, begin, and end don't go into detail on the range of dates that the functions will accept. Is this intentional?

In the Water Data APIs vignette, it does a few things with the time input, and there's a section that covers the time zone reference table, but it might be nice to show off using UTC offsets in an example, or the really lovely time zone example I highlight above, where you don't have to futz with offsets at all.

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.

2 participants