hasTimeFormat: Do Timestamps have the expected Format?

Description Usage Arguments Examples

View source: R/matchingTimeFormat.R

Description

Checks if timestamps are formatted according to timeformat

Usage

1
hasTimeFormat(timestamps, timeformat = NULL, method = 1L)

Arguments

timestamps

character strings representing timestamps.

timeformat

character string giving a date-time format as used by strptime.

method

Method used to do the check. 1: Check based on pattern matching 2: Check whether as.POSIXct returns valid time objects and if re-formatting these objects are identical to the original timestamps. The simple check should be much faster for many timestamps to be checked.

Examples

1
2
3
4
5
6
7
hasTimeFormat("1.1.2012", "%d.%m.%Y") # TRUE
hasTimeFormat("1.13.2012", "%d.%m.%Y") # FALSE
hasTimeFormat("1/31/2012", "%m/%d/%Y") # TRUE
hasTimeFormat("31/1/2012", "%m/%d/%Y") # FALSE

hasTimeFormat(c("1.1.", "1.13.", "12.12.", "32.1."), "%d.%m.") 
#               TRUE     FALSE    TRUE      FALSE

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