datetimeoffset-invalid {datetimeoffset} | R Documentation |
Invalid datetimeoffset datetimes
Description
invalid_detect()
detects invalid datetimes.
invalid_any()
returns TRUE if any datetimes are invalid.
invalid_count()
returns number of invalid datetimes.
invalid_remove()
removes invalid datetimes.
invalid_resolve()
resolves invalid datetimes.
Usage
## S3 method for class 'datetimeoffset'
invalid_detect(x)
## S3 method for class 'datetimeoffset'
invalid_resolve(x, ..., invalid = "NA", nonexistent = "NA")
## S3 method for class 'datetimeoffset'
invalid_any(x)
## S3 method for class 'datetimeoffset'
invalid_count(x)
## S3 method for class 'datetimeoffset'
invalid_remove(x)
Arguments
x |
A |
... |
Ignored. |
invalid |
Invalid date resolution strategy. See |
nonexistent |
Nonexistent (because of DST spring forward) time resolution strategy.
See |
Details
datetimeoffset()
datetimes can be considered invalid for three main reasons:
An invalid "calendar date" such as
"2020-02-30"
(there are less than 30 days in February).A "nonexistent" datetime due to a Daylight Savings Time "spring forward" such as
"2020-03-08T02:59:59[America/Los_Angeles]"
Incorrect UTC offsets such as
"2020-03-08T01:59:59-08[America/New_York]"
(that particular Eastern time has a UTC offset of-05
)
Value
invalid_detect()
, invalid_remove()
, and invalid_resolve()
return datetimeoffset()
vectors.
invalid_count()
returns an integer and invalid_any()
returns a logical value.
Examples
# invalid date because April only has 30 days
dts <- c("2019-04-30T03:30:00", "2019-04-31T02:30:00")
dts <- as_datetimeoffset(dts)
clock::invalid_detect(dts)
clock::invalid_any(dts)
clock::invalid_count(dts)
clock::invalid_remove(dts)
clock::invalid_resolve(dts)
clock::invalid_resolve(dts, invalid = "previous")
clock::invalid_resolve(dts, invalid = "previous-day")
# non-existent time because of DST "spring forward"
if ("America/Los_Angeles" %in% OlsonNames()) {
dt <- as_datetimeoffset("2020-03-08T02:59:59[America/Los_Angeles]")
print(clock::invalid_detect(dt))
clock::invalid_resolve(dt, nonexistent = "roll-forward")
}
# incorrect UTC offsets
if ("America/New_York" %in% OlsonNames()) {
dt <- as_datetimeoffset("2020-03-08T01:59:59-08[America/New_York]")
print(clock::invalid_detect(dt))
clock::invalid_resolve(dt)
}