From f9073de046904e1ac775a74b3f783b1d2fd95b85 Mon Sep 17 00:00:00 2001
From: unknown <ldecicco@usgs.gov>
Date: Wed, 22 Apr 2015 11:23:19 -0500
Subject: [PATCH] Fixed timezone + daylight savings bug.

---
 R/importWaterML1.r | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/R/importWaterML1.r b/R/importWaterML1.r
index afc12c97..9d3112b1 100644
--- a/R/importWaterML1.r
+++ b/R/importWaterML1.r
@@ -87,6 +87,10 @@
 #' fullPath <- file.path(filePath, fileName)
 #' imporFile <- importWaterML1(fullPath,TRUE)
 #'
+#'#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")
+#'
 importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){
   
   if(file.exists(obs_url)){
@@ -273,13 +277,13 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){
               }
             }
             
-            if(tz != ""){
-              attr(datetime, "tzone") <- tz
-              df$tz_cd <- rep(tz, nrow(df))
-            } else {
-              attr(datetime, "tzone") <- "UTC"
-              df$tz_cd <- rep("UTC", nrow(df))
-            }
+#             if(tz != ""){
+#               attr(datetime, "tzone") <- tz
+#               df$tz_cd <- rep(tz, nrow(df))
+#             } else {
+#               attr(datetime, "tzone") <- "UTC"
+#               df$tz_cd <- rep("UTC", nrow(df))
+#             }
 
             
           } else {
@@ -308,9 +312,6 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){
         }
         
         columnsOrderd <- columnsOrdered[columnsOrdered %in% names(df)]
-        
-        
-        
         df <- df[,columnsOrderd]
                         
         if (is.null(mergedDF)){
@@ -456,6 +457,14 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){
     mergedDF <- data.frame()
   }
 
+  if(tz != ""){
+    attr(mergedDF$dateTime, "tzone") <- tz
+    mergedDF$tz_cd <- rep(tz, nrow(mergedDF))
+  } else {
+    attr(mergedDF$dateTime, "tzone") <- "UTC"
+    mergedDF$tz_cd <- rep("UTC", nrow(mergedDF))
+  }
+
   variableInformation$noDataValue <- rep(NA, nrow(variableInformation))
   
   row.names(mergedDF) <- NULL
-- 
GitLab