getEqualStepRanges: Sequences of Date Time Objects With Equal Time Step

Description Usage Arguments Examples

View source: R/getEqualStepRanges.R

Description

Sequences of Date Time Objects With Equal Time Step

Usage

1

Arguments

times

vector of POSIXct objects

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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)

# 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)

# 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)

# Check if the original date and time objects could be reproduced
identical(good_times, times)

KWB-R/kwb.datetime documentation built on July 9, 2021, 10:28 p.m.