datetime_precision {datetimeoffset}R Documentation

Datetime precision

Description

datetime_precision() returns the "precision" of a datetime vector's datetimes. precision_to_int() converts the precision to an integer.

Usage

datetime_precision(x, ...)

## S3 method for class 'datetimeoffset'
datetime_precision(x, range = FALSE, unspecified = FALSE, ...)

## S3 method for class 'clock_calendar'
datetime_precision(x, ...)

## S3 method for class 'clock_time_point'
datetime_precision(x, ...)

## S3 method for class 'clock_zoned_time'
datetime_precision(x, ...)

## S3 method for class 'nanotime'
datetime_precision(x, ...)

precision_to_int(precision)

Arguments

x

A datetime vector. Either datetimeoffset(), a "clock" "calendar", or a "clock" "time".

...

Used by some S3 methods.

range

If TRUE return just the minimum and maximum "precision".

unspecified

If TRUE use the smallest non-missing component's as the precision even if there is a missing value for a larger component.

precision

A datetime precision (as returned by datetime_precision()).

Value

datetime_precision() returns a character vector of precisions. Depending on the object either "missing", "year", "quarter", "month", "week", "day", "hour", "minute", "second", "millisecond", "microsecond", or "nanosecond". precision_to_int() returns an integer vector.

Examples

  dts <- as_datetimeoffset(c("2020", "2020-04-10", "2020-04-10T10:10"))
  datetime_precision(dts)
  datetime_precision(dts, range = TRUE)

  dt <- datetimeoffset(2020, NA_integer_, 10)
  datetime_precision(dt)
  datetime_precision(dt, unspecified = TRUE)

  precision_to_int("year") < precision_to_int("day")

  library("clock")
  datetime_precision(year_month_day(1918, 11, 11))
  datetime_precision(sys_time_now())
  datetime_precision(zoned_time_now(Sys.timezone()))

[Package datetimeoffset version 0.3.1 Index]