This function tries to overcome some problems that may arise when using as.POSIXct. It can handle timestamps that originate from a clock that switches between standard time and summer time as well as those originating from a clock that stays in standard time over the whole year. See vignette("text_to_posixct", package = "kwb.datetime") for details. It also tries to find a convenient format description string.

textToEuropeBerlinPosix(x, format = NULL, switches = TRUE, dbg = TRUE, ...)

Arguments

x

vector of text (i.e. character) timestamps

format

format string describing the format of a timestamp, such as " placeholders. If not given or NULL, the function tries to guess the format from the first timestamp given in x.

switches

if TRUE (the default), the timestamps are assumed to originate from a clock that switches between standard time and summer time. Otherwise (switches = FALSE) timestamps are assumed to originate from a clock that stays in standard time over the whole year.

dbg

if TRUE debug messages are shown

...

further arguments passed to reformatTimestamp (only relevant if switches = TRUE)

Value

vector of POSIXct objects

Details

When reading timestamps that observe Daylight Saving, it is required that the timestamps in x are ordered by time, which should be the case if they were recorded by a measuring device.

Examples

# Test the functions with the following "switch" days kwb.datetime::date_range_CEST(2019)
#> begin end #> "2019-03-31" "2019-10-27"
t1 <- textToEuropeBerlinPosix(c("31.03.2019 01:00", "31.03.2019 03:00"))
#> Guessing time format ... ok. (0.01s) #> Converting 2 timestamps to POSIXct ... ok. (0.01s)
t2 <- textToEuropeBerlinPosix(c("31.03.2019 01:00", "31.03.2019 02:00"), switches = FALSE)
#> Guessing time format ... ok. (0.01s) #> Converting 2 timestamps to POSIXct ... ok. (0.00s)
identical(t1, t2)
#> [1] TRUE
t3 <- textToEuropeBerlinPosix(c("27.10.2019 02:00", "27.10.2019 02:00"))
#> Guessing time format ... ok. (0.01s) #> Converting 2 timestamps to POSIXct ... ok. (0.01s)
t4 <- textToEuropeBerlinPosix(c("27.10.2019 01:00", "27.10.2019 02:00"), switches = FALSE)
#> Guessing time format ... ok. (0.01s) #> Converting 2 timestamps to POSIXct ... ok. (0.00s)
identical(t3, t4)
#> [1] TRUE
kwb.datetime::textToEuropeBerlinPosix(c( "2017-10-29 01:30:00", # 1: CEST "2017-10-29 02:00:00", # 2: CEST "2017-10-29 02:30:00", # 3: CEST "2017-10-29 02:00:00", # 4: CET "2017-10-29 02:30:00", # 5: CET "2017-10-29 03:00:00" # 6: CET ))
#> Guessing time format ... ok. (0.01s) #> Converting 6 timestamps to POSIXct ... ok. (0.01s)
#> [1] "2017-10-29 01:30:00 CEST" "2017-10-29 02:00:00 CEST" #> [3] "2017-10-29 02:30:00 CEST" "2017-10-29 02:00:00 CET" #> [5] "2017-10-29 02:30:00 CET" "2017-10-29 03:00:00 CET"