ston, TX?

    
    
    meeting <- [ymd_hms](../reference/ymd_hms.html)("2011-07-01 09:00:00", tz = "Pacific/Auckland")
    [with_tz](../reference/with_tz.html)(meeting, "America/Chicago")
    #> [1] "2011-06-30 16:00:00 CDT"

So the meetings occurred at 4:00 Hadley’s time (and the day before no less).
Of course, this was the same actual moment of time as 9:00 in New Zealand. It
just appears to be a different day due to the curvature of the Earth.

What if Hadley made a mistake and signed on at 9:00 his time? What time would
it then be my time?

    
    
    mistake <- [force_tz](../reference/force_tz.html)(meeting, "America/Chicago")
    [with_tz](../reference/with_tz.html)(mistake, "Pacific/Auckland")
    #> [1] "2011-07-02 02:00:00 NZST"

His call would arrive at 2:00 am my time! Luckily he never did that.

##  Time Intervals

You can save an interval of time as an Interval class object with lubridate.
This is quite useful! For example, my stay in Auckland lasted from June 4,
2011 to August 10, 2011 (which we’ve already saved as arrive and leave). We
can create this interval in one of two ways:

    
    
    auckland <- [interval](../reference/interval.html)(arrive, leave)
    auckland
    #> [1] 2011-06-04 12:00:00 NZST--2011-08-10 14:00:00 NZST
    auckland <- arrive [%--%](../reference/interval.html) leave
    auckland
    #> [1] 2011-06-04 12:00:00 NZST--2011-08-10 14:00:00 NZST

My mentor at the University of Auckland, Chris, traveled to various
conferences that year including the Joint Statistical Meetings (JSM). This
took him out of the country from July 20 until the end of August.

    
    
    jsm <- [interval](../reference/interval.html)([ymd](../reference/ymd.html)(20110720, tz = "Pacific/Auckland"), [ymd](../reference/ymd.html)(20110831, tz = "Pacific/Auckland"))
    jsm
    #> [1] 2011-07-20 NZST--2011-08-31 NZST

Will my visit overlap with and his travels? Yes.

    
    
    [int_overlaps](../reference/interval.html)(jsm, auckland)
    #> [1] TRUE

Then I better make hay while the sun shines! For what part of my visit will
Chris be there?

    
    
    [setdiff](https://generics.r-lib.org/reference/setops.html)(auckland, jsm)
    #> [1] 2011-06-04 12:00:00 NZST--2011-07-20 NZST

Other functions that work with intervals include ` int_start ` , ` int_end ` ,
` int_flip ` , ` int_shift ` , ` int_aligns ` , ` union ` , ` intersect ` , `
setdiff ` , and ` %within% ` .

##  Arithmetic with date times

Intervals are specific time spans (because they are tied to specific dates),
but lubridate also supplies two general time span classes: Durations and
Periods. Helper functions for creating periods are named after the units of
time (plural). Helper functions for creating durations follow the same format
but begin with a “d” (for duration) or, if you prefer, and “e” (for exact).

    
    
    [minutes](../reference/period.html)(2) ## period
    #> [1] "2M 0S"
    [dminutes](../reference/duration.html)(2) ## duration
    #> [1] "120s (~2 minutes)"

Why two classes? Because the timeline is not as reliable as the number line.
The Duration class will always supply mathematically precise results. A
duration year will always equal 365 days. Periods, on the other hand,
fluctuate the same way the timeline does to give intuitive results. This makes
them useful for modeling clock times. For example, durations will be honest in
the face of a leap year, but periods may return what you want:

    
    
    [leap_year](../reference/leap_year.html)(2011) ## regular year
    #> [1] FALSE
    [ymd](../reference/ymd.html)(20110101) + [dyears](../reference/duration.html)(1)
    #> [1] "2012-01-01 06:00:00 UTC"
    [ymd](../reference/ymd.html)(20110101) + [years](../reference/period.html)(1)
    #> [1] "2012-01-01"
    
    [leap_year](../reference/leap_year.html)(2012) ## leap year
    #> [1] TRUE
    [ymd](../reference/ymd.html)(20120101) + [dyears](../reference/duration.html)(1)
    #> [1] "2012-12-31 06:00:00 UTC"
    [ymd](../re