Find Time Format matching a Timestamp
matchingTimeFormat( timestamp, timeFormats = getTimeFormats(), method = 1L, warn = TRUE, failureValue = NULL )
timestamp | character timestamp to be checked against different possible timstamp formats |
---|---|
timeFormats | vector of possible time formats with placeholders
(year),
described for |
method | passed to |
warn | if |
failureValue | value returned in case that no matching format was found.
Default: |
first time format in timeformats that matches the given timestamp. NULL is returned if none of the given timeformats matches.
# Convert a character timestamp of which the format can be one of two # possible formats into a POSIXct-object possibleFormats <- c("%d.%m.%Y", "%d/%m/%Y") x <- "14.01.2015" t1 <- hsToPosix(x, format = matchingTimeFormat(x, possibleFormats)) # In fact this is what stringToPosix does (for only one timestamp) t2 <- stringToPosix(x, formats = possibleFormats) stopifnot(identical(t1, t2)) # You get a warning if none of the possible formats matches matchingTimeFormat("01.14.2015", possibleFormats)#> Warning: No matching format found for timestamp '01.14.2015'. Considered formats: #> '%d.%m.%Y', #> '%d/%m/%Y'#> NULL