MazamaCoreUtils (version 0.4.2)

timeStamp: Character representation of a POSIXct

Description

Uses incoming parameters to return a pair of POSIXct times in the proper order. Both start and end times will have lubridate::floor_date() applied to get the nearest unit unless ceilingEnd = TRUE in which case the end time will will have lubridate::ceiling_date() applied.

The required timezone parameter must be one of those found in OlsonNames.

Formatting output is are affected by both style:

  • "ymdhms"

  • "julian"

  • "clock"

and unit which determines the temporal precision of the generated representation:

  • "year"

  • "month"

  • "day"

  • "hour"

  • "min"

  • "sec"

If `style == "julian"` && `unit = "month"``, the timestamp will contain the Julian day associated with the beginning of the month.

Usage

timeStamp(datetime = NULL, timezone = NULL, unit = "sec", style = "ymdhms")

Arguments

datetime

Vector of character or integer datetimes in Ymd[HMS] format (or POSIXct).

timezone

Olson timezone used to interpret incoming dates (required).

unit

Units used to determine precision of generated time stamps.

style

Style of representation, Default = "ymdhms".

Value

A vector of time stamps.

POSIXct inputs

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. This is different from the behavior of parse_date_time (which powers this function), which will force POSIXct inputs into a new timezone, altering the physical moment of time the input represents.

Examples

Run this code
# NOT RUN {
datetime <- parseDatetime("2019-01-08 12:30:15", timezone = "UTC")

timeStamp(datetime, "UTC", unit = "year")
timeStamp(datetime, "UTC", unit = "month")
timeStamp(datetime, "UTC", unit = "month", style = "julian")
timeStamp(datetime, "UTC", unit = "day")
timeStamp(datetime, "UTC", unit = "day", style = "julian")
timeStamp(datetime, "UTC", unit = "hour")
timeStamp(datetime, "UTC", unit = "min")
timeStamp(datetime, "UTC", unit = "sec")
timeStamp(datetime, "UTC", unit = "sec", style = "julian")
timeStamp(datetime, "UTC", unit = "sec", style = "clock")
timeStamp(datetime, "America/Los_Angeles", unit = "sec", style = "clock")

# }

Run the code above in your browser using DataCamp Workspace