diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2016-12-22 11:06:57 +0100 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2016-12-22 11:06:57 +0100 |
commit | bba2cf3a70849ba86f37520d3e909cf1c706f416 (patch) | |
tree | 57418b23b3da0ca1593ce842b3c8c90859636852 /R | |
parent | 5a04ad3061c1484b45703e44149f49ec97cfbf15 (diff) |
Fix reading in times from .out files
The code from the previous commit was broken. Also, the time
zone for the times that are read is now wet to 'UTC', in order to
avoid setting different time zones due to daylight savings, which
introduces artificial one-hour offsets on changeover days.
Diffstat (limited to 'R')
-rw-r--r-- | R/TOXSWA_cwa.R | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/R/TOXSWA_cwa.R b/R/TOXSWA_cwa.R index fcd070a..8de18a4 100644 --- a/R/TOXSWA_cwa.R +++ b/R/TOXSWA_cwa.R @@ -207,10 +207,11 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa", cwa <- subset(cwa_all_segments, segment == self$segment, c("datetime", "t", "segment", "cwa", "cwa_tot")) lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C") - cwa$datetime <- strptime(cwa$datetime, "%d-%b-%Y-%H:%M") + cwa$datetime <- strptime(cwa$datetime, "%d-%b-%Y-%H:%M", tz = "UTC") Sys.setlocale("LC_TIME", lct) startyear = format(cwa$datetime[1], "%Y") - firstjan <- strptime(paste0(startyear, "-01-01"), "%Y-%m-%d") + firstjan <- strptime(paste0(startyear, "-01-01"), "%Y-%m-%d", + tz = "UTC") cwa$t_firstjan <- as.numeric(difftime(cwa$datetime, firstjan, units = "days")) @@ -262,15 +263,16 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa", cwa <- data.frame( datetime = as.character(cwa_all_segments$X2), t = cwa_all_segments$X1, - cwa = cwa_all_segments[[3 + segment]] + cwa = cwa_all_segments[[3 + segment]], + stringsAsFactors = FALSE ) - # Append time "-00h00" to datetime if there is not time (only 11 characters) + # Append time "-00h00" to datetime if there is no time (only 11 characters) # The fact that the time is missing at 00h00 was reported to Mark # Liedekerke, Wim Beltman, Paulien Adriaanse, and Chris Lythgo # on 14 December 2016 cwa <- within(cwa, - datetime <- ifelse(nchar(datetime == 11), + datetime <- ifelse(nchar(datetime) == 11, paste0(datetime, "-00h00"), datetime)) @@ -280,11 +282,12 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa", cwa$cwa_tot = cwa_tot_all_segments[[3 + segment]] } lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C") - cwa$datetime <- strptime(cwa$datetime, "%d-%b-%Y-%Hh%M") + cwa$datetime <- strptime(cwa$datetime, "%d-%b-%Y-%Hh%M", tz = "UTC") Sys.setlocale("LC_TIME", lct) startyear = format(cwa$datetime[1], "%Y") - firstjan <- strptime(paste0(startyear, "-01-01"), "%Y-%m-%d") + firstjan <- strptime(paste0(startyear, "-01-01"), "%Y-%m-%d", + tz = "UTC") cwa$t_firstjan <- as.numeric(difftime(cwa$datetime, firstjan, units = "days")) t_max = cwa[which.max(cwa$cwa), "t"] |