Learn R Programming

MazamaCoreUtils (version 0.6.2)

timeRange: Create a POSIXct time range

Description

Create an ordered two-element POSIXct time range from start and end datetime values.

Usage

timeRange(
  starttime = NULL,
  endtime = NULL,
  timezone = NULL,
  unit = "sec",
  ceilingStart = FALSE,
  ceilingEnd = FALSE
)

Value

Two-element POSIXct vector ordered from earliest to latest.

Arguments

starttime

Desired start datetime.

endtime

Desired end datetime.

timezone

Olson timezone used to interpret incoming datetimes.

unit

Unit used for rounding. Passed to lubridate::floor_date() or lubridate::ceiling_date().

ceilingStart

Logical specifying whether to round the start time up instead of down.

ceilingEnd

Logical specifying whether to round the end time up instead of down.

POSIXct inputs

When startdate or enddate are already POSIXct values, they are first converted to timezone with lubridate::with_tz() without changing the represented instant in time.

Details

Input values are converted with parseDatetime() using the required timezone argument. The resulting start and end times are sorted so the earlier time is always returned first.

By default, both times are rounded down with lubridate::floor_date() using the requested unit. Set ceilingStart = TRUE or ceilingEnd = TRUE to round either endpoint up with lubridate::ceiling_date() instead.

Examples

Run this code
timeRange(
  starttime = "2019-01-08 10:12:15",
  endtime = 20190109102030,
  timezone = "UTC"
)

timeRange(
  starttime = "2019-01-08 10:12:15",
  endtime = "2019-01-09 10:20:30",
  timezone = "UTC",
  unit = "hour"
)

Run the code above in your browser using DataLab