fit_to_timeline: Fit a POSIXlt date-time to the timeline

Description Usage Arguments Value Examples

Description

The POSIXlt format allows you to create instants that do not exist in real life due to daylight savings time and other conventions. fit_to_timeline matches POSIXlt date-times to a real times. If an instant does not exist, fit to timeline will replace it with an NA. If an instant does exist, but has been paired with an incorrect timezone/daylight savings time combination, fit_to_timeline returns the instant with the correct combination.

Usage

1
fit_to_timeline(lt, class = "POSIXct", simple = FALSE)

Arguments

lt

a POSIXlt date-time object.

class

a character string that describes what type of object to return, POSIXlt or POSIXct. Defaults to POSIXct. This is an optimization to avoid needless conversions.

simple

if TRUE, lubridate makes no attempt to detect meaningless time-dates or to correct time zones. No NAs are produced and the most meaningful valid dates are returned instead. See examples.

Value

a POSIXct or POSIXlt object that contains no illusory date-times

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
27
28
29
30
31
32
33
34
35
36
37
## Not run: 
tricky <- structure(list(sec   = c(5,    0,    0,    -1),
                         min   = c(0L,   5L,   5L,   0L),
                         hour  = c(2L,   0L,   2L,   2L),
                         mday  = c(4L,   4L,   14L,  4L),
                         mon   = c(10L,  10L,  2L,   10L),
                         year  = c(112L, 112L, 110L, 112L),
                         wday  = c(0L,   0L,   0L,   0L),
                         yday  = c(308L, 308L, 72L,  308L),
                         isdst = c(1L,   0L,   0L,   1L)),
                    .Names = c("sec", "min", "hour", "mday", "mon",
                               "year", "wday", "yday",  "isdst"),
                    class = c("POSIXlt", "POSIXt"),
                    tzone = c("America/Chicago", "CST", "CDT"))
tricky
## because clocks "fall back" to 1:00 CST

## CDT, not CST at this instant

##because clocks "spring forward" past this time
## for daylight savings

## has deceptive internal structure

fit_to_timeline(tricky)
[1] "2012-11-04 02:00:05 CST" "2012-11-04 00:05:00 CDT"
[4] NA                        "2012-11-04 01:59:59 CDT"

## with correct timezone & DST combination

## with correct timezone & DST combination


fit_to_timeline(tricky, simple = TRUE)
## Reduce to valid time-dates by extrapolating CDT and CST zones

## End(Not run)


Search within the lubridate package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.