as_daytime: Retrieve minute of day

View source: R/daytime__class.R

as_daytimeR Documentation

Retrieve minute of day

Description

Retrieve minute of day

Usage

as_daytime(x, ...)

## S3 method for class 'POSIXt'
as_daytime(x, rational = FALSE, ...)

## S3 method for class 'numeric'
as_daytime(x, rational = attr(x, "rational"), ...)

## S3 method for class 'circular'
as_daytime(x, rational = attr(x, "rational"), warn_circular = TRUE, ...)

## S3 method for class 'character'
as_daytime(x, rational = FALSE, ...)

## S3 method for class 'integer'
as_daytime(x, ...)

Arguments

x

value from which to determine the minute of day value; typically inherits from character or POSIXt, but methods are available for circular and numeric as well

...

arguments passed to as.POSIXct. See details.

rational

logical. If FALSE, values are rounded down to the nearest whole minute; if TRUE, real-numbered values are returned with the decimal portions reflecting seconds

warn_circular

logical. Issue a warning if class circular is being removed?

Details

If x inherits from character, casting to POSIXt will be attempted. Arguments can be passed to as.POSIXct to assist with this, notably the format and tz arguments. Presumably the timezone should not matter, except perhaps during a daylight saving transition hour. But it is always safest to pass in POSIX-formatted data that you have vetted yourself.

Value

a daytime object

Examples


t1_char <- "00:01:30"
t1 <- as.POSIXct(t1_char, "UTC", format = "%H:%M:%S")

## Methods exist to give comparable output from character and POSIX inputs
as_daytime(t1_char, format = "%H:%M:%S")
as_daytime(t1)

as_daytime(t1, TRUE)

## Beware of silent timezone changes. System will
## assume your local timezone unless told otherwise!
as_daytime(
  strftime(t1, "%H:%M:%S", "EST"),
  format = "%H:%M:%S"
)


paulhibbing/daytime documentation built on July 13, 2022, 6:32 p.m.