Commit 0142053a authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

What if daylight savings?

parent 818ebd63
......@@ -89,7 +89,8 @@
#'
#' # Timezone change with specified local timezone:
#' tzURL <- constructNWISURL("04027000", c("00300","63680"), "2011-11-05", "2011-11-07","uv")
#' tzIssue <- importWaterML1(tzURL, TRUE, "America/Chicago")
#' tzIssue <- importWaterML1(tzURL,
#' asDateTime = TRUE, tz = "America/Chicago")
#'
#' # raw XML
#' url <- constructNWISURL(service = 'dv', siteNumber = '02319300', parameterCd = "00060",
......@@ -197,7 +198,8 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
}
#^^setting tz in as.POSIXct just sets the attribute, does not convert the time!
attr(dateTime, 'tzone') <- tz
# Set to UTC now, convert the whole thing to tz later.
attr(dateTime, 'tzone') <- "UTC"
tzCol <- rep(tz,nObs)
} else {
tzCol <- rep(defaultTZ, nObs)
......@@ -241,7 +243,7 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
obsDF <- data.frame(dateTime=character(0), tz_cd=character(0), stringsAsFactors = FALSE)
if(asDateTime){
obsDF$dateTime <- as.POSIXct(obsDF$dateTime)
attr(obsDF$dateTime, "tzone") <- tz
attr(obsDF$dateTime, "tzone") <- "UTC"
}
}
}
......@@ -301,13 +303,14 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
by = sameSite_simNames,
all=TRUE)
na.omit.unique <- function(x){
if(all(is.na(x))) NA else na.omit(x)
if(all(is.na(x))) NA else stats::na.omit(x)
}
if(any(duplicated(sameSite[,c("agency_cd", "site_no",
"dateTime", "tz_cd")]))){
types <- lapply(sameSite, class)
sameSite <- aggregate(.~ agency_cd + site_no + dateTime + tz_cd,
sameSite <- stats::aggregate(.~ agency_cd + site_no + dateTime + tz_cd,
data = sameSite,
FUN = na.omit.unique, na.action=NULL )
sameSite[,which(types == "numeric")] <- sapply(sameSite[,which(types == "numeric")], as.numeric)
......@@ -354,8 +357,9 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
#move tz column to far right and sort by increasing site number to be consistent with old version
mergedNames <- names(mergedDF)
tzLoc <- grep("tz_cd", names(mergedDF))
attr(mergedDF$dateTime, 'tzone') <- tz
mergedDF <- mergedDF[c(mergedNames[-tzLoc],mergedNames[tzLoc])]
mergedDF <- mergedDF[order(mergedDF$site_no, mergedDF$dateTime),]
###############################################################
names(mergedDF) <- make.names(names(mergedDF))
......
......@@ -92,7 +92,8 @@ inactiveAndAcitive <- importWaterML1(inactiveAndAcitive)
# Timezone change with specified local timezone:
tzURL <- constructNWISURL("04027000", c("00300","63680"), "2011-11-05", "2011-11-07","uv")
tzIssue <- importWaterML1(tzURL, TRUE, "America/Chicago")
tzIssue <- importWaterML1(tzURL,
asDateTime = TRUE, tz = "America/Chicago")
# raw XML
url <- constructNWISURL(service = 'dv', siteNumber = '02319300', parameterCd = "00060",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment