dateSequence | R Documentation |
Uses incoming parameters to return a seqeunce of POSIXct
times at
local midnight in the specified timezone
. The first returned time will
be midnight of the requested startdate
. The final returned time will
be midnight (at the beginning) of the requested enddate
.
The ceilingEnd
argument addresses the ambiguity of a phrase like:
"August 1-8". With ceilingEnd = FALSE
(default) this pharse means
"through the beginning of Aug 8". With ceilingEnd = TRUE
it means
"through the end of Aug 8".
The required timezone
parameter must be one of those found in
OlsonNames
.
Dates can be anything that is understood by
lubrdiate::parse_date_time()
using the Ymd[HMS]
orders. This
includes:
"YYYYmmdd"
"YYYYmmddHHMMSS"
"YYYY-mm-dd"
"YYYY-mm-dd H"
"YYYY-mm-dd H:M"
"YYYY-mm-dd H:M:S"
All hour-minute-second information is removed after parsing.
dateSequence(
startdate = NULL,
enddate = NULL,
timezone = NULL,
ceilingEnd = FALSE
)
startdate |
Desired start datetime (ISO 8601). |
enddate |
Desired end datetime (ISO 8601). |
timezone |
Olson timezone used to interpret dates (required). |
ceilingEnd |
Logical instruction to apply
|
A vector of POSIXct
s at midnight local time.
When startdate
or enddate
are already POSIXct
values,
they are converted to the timezone specified by timezone
without
altering the physical instant in time the input represents. Only after
conversion are they floored to midnight local time
The main utility of this function is that it respects "clock time" and returns times associated with midnight regardless of daylight savings. This is in contrast to 'seq.Date(from, to, by = "day")' which creates a sequence of datetimes always separated by 24 hours.
library(MazamaCoreUtils)
dateSequence("2019-11-01", "2019-11-08", timezone = "America/Los_Angeles")
dateSequence("2019-11-01", "2019-11-07", timezone = "America/Los_Angeles",
ceilingEnd = TRUE)
# Observe the handling of daylight savings
datetime <- dateSequence("2019-11-01", "2019-11-08",
timezone = "America/Los_Angeles")
datetime
lubridate::with_tz(datetime, "UTC")
# Passing in POSIXct values preserves the instant in time before flooring --
# midnight Tokyo time is the day before in UTC
jst <- dateSequence(20190307, 20190315, timezone = "Asia/Tokyo")
jst
dateSequence(jst[1], jst[7], timezone = "UTC")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.