Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.

Commit f7dbb46

Browse files
committed
fixed similar timezone issues that RMevents was having. Fixed in a different way - uses lubridate to find the timezone of the input data, then maintain that tz later on. This avoids R using the timezone of the computer when tz gets dropped through the loop.
1 parent daccd7a commit f7dbb46

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export(RMintensity)
1010
export(RMprep)
1111
export(discharge_events)
1212
import(dplyr)
13+
importFrom(lubridate,tz)
1314
importFrom(rlang,sym)

R/RMevents_sample.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#' @param bdate character column name in dfsamples for the beginning of the sampling period
1616
#' @param edate character column name in dfsamples for the ending of the sampling period
1717
#' @return list of storms and storms2
18+
#' @importFrom lubridate tz
1819
#' @export
1920
#' @examples
2021
#' RDB <- CedarRRain
@@ -48,6 +49,8 @@ RMevents_sample <- function(df,
4849
startRainDates <- numeric()
4950
endRainDates <- numeric()
5051
tipsbystorm <- data.frame()
52+
53+
rain_timezone <- lubridate::tz(df[,time])
5154

5255
for (i in 1:nrow(dfsamples)){
5356
beginRow <- max(which(df[,time]<dfsamples[i,bdate])+1)
@@ -109,8 +112,8 @@ RMevents_sample <- function(df,
109112
}
110113
tipsbystorm <- sub_tips
111114
} else {
112-
startRainDates <- as.POSIXct(c(startRainDates,BD), origin = "1970-01-01")
113-
endRainDates <- as.POSIXct(c(endRainDates,ED), origin = "1970-01-01")
115+
startRainDates <- as.POSIXct(c(startRainDates,BD), origin = "1970-01-01", tz = rain_timezone)
116+
endRainDates <- as.POSIXct(c(endRainDates,ED), origin = "1970-01-01", tz = rain_timezone)
114117
if (nrow(sub_tips) > 0) {
115118
event <- event + 1
116119
} else {

0 commit comments

Comments
 (0)