Sequences of Date Time Objects With Equal Time Step

getEqualStepRanges(times)

Arguments

times

vector of POSIXct objects

Examples

# Generate a sequence of date and time objects as_berlin_posix <- function(x) as.POSIXct(x, tz = "Europe/Berlin") times <- seq( from = as_berlin_posix("2019-01-01"), to = as_berlin_posix("2020-01-01"), by = 3600 ) # As expected, exactly one sequence of equal time step is found: getEqualStepRanges(times)
#> from to from_time to_time step #> 1 1 8761 2019-01-01 2020-01-01 1 hours
# Simulate the case that timestamps were read from a text file and converted # with as.POSIXct() timestamps <- as.character(times) new_times <- as.POSIXct(timestamps, tz = "Europe/Berlin") # Show the sequences of equal time steps again getEqualStepRanges(new_times)
#> from to from_time to_time step #> 1 1 7178 2019-01-01 00:00:00 2019-10-27 02:00:00 3600 secs #> 2 7178 7179 2019-10-27 02:00:00 2019-10-27 02:00:00 0 secs #> 3 7179 7180 2019-10-27 02:00:00 2019-10-27 03:00:00 7200 secs #> 4 7180 8761 2019-10-27 03:00:00 2020-01-01 00:00:00 3600 secs
# What happened? The timestamp 2019-10-27 02:00 appears twice! Once in CEST # and once in CET. Use a helper function that assigns CEST and CET as # required: good_times <- textToEuropeBerlinPosix(timestamps)
#> Guessing time format ... ok. (0.01s) #> Converting 8761 timestamps to POSIXct ... ok. (0.15s)
# Check if the original date and time objects could be reproduced identical(good_times, times)
#> [1] TRUE