Skip to content

Commit

Permalink
Merge pull request #739 from ldecicco-USGS/main
Browse files Browse the repository at this point in the history
Fix WQP siteInfo attribute bug
  • Loading branch information
ldecicco-USGS authored Dec 3, 2024
2 parents e27395d + 46860bc commit 573da06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 18 additions & 1 deletion R/importWQP.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,34 @@ parse_WQP <- function(retval, tz = "UTC"){
dateCols_to_convert <- NA
for(date_col in dateCols){

# Legacy:
time_col <- gsub("Date", "Time", date_col)
tz_col <- gsub("Date", "TimeZone", date_col)
tz_col <- paste0(time_col, ".TimeZoneCode")
time_col <- paste0(time_col, ".Time")

# WQX3:
time_col_wqx3 <- gsub("Date", "Time", date_col)
tz_col_wqx3 <- gsub("Date", "TimeZone", date_col)

if(all(c(date_col, time_col, tz_col) %in% names(retval))){
# Legacy
if(!all(is.na(retval[[date_col]]))){
retval <- create_dateTime(retval,
date_col = date_col,
time_col = time_col,
tz_col = tz_col,
tz = tz)
}

} else if(all(c(date_col, time_col_wqx3, tz_col_wqx3) %in% names(retval))){
# WQX3
if(!all(is.na(retval[[date_col]]))){
retval <- create_dateTime(retval,
date_col = date_col,
time_col = time_col_wqx3,
tz_col = tz_col_wqx3,
tz = tz)
}
} else {
# This is the legacy pattern:
time_col <- gsub("Date", "Time.Time", date_col)
Expand Down
6 changes: 4 additions & 2 deletions R/readWQPdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ readWQPdata <- function(...,

attr(retval, "legacy") <- legacy

if (!all(is.na(retval)) && !ignore_attributes) {
params <- list(...)
if (!all(is.na(retval)) &&
!ignore_attributes &&
!service %in% c("Station", "StationWQX")) {
params <- convertLists(...)
params <- params[!names(params) %in% c("dataProfile", "service")]
retval <- create_WQP_attributes(retval, params)
}
Expand Down

0 comments on commit 573da06

Please sign in to comment.