Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

new_date

Date, date-time, and duration S3 classes


Description

  • A date (Date) is a double vector. Its value represent the number of days since the Unix "epoch", 1970-01-01. It has no attributes.

  • A datetime (POSIXct is a double vector. Its value represents the number of seconds since the Unix "Epoch", 1970-01-01. It has a single attribute: the timezone (tzone))

  • A duration (difftime)

Usage

new_date(x = double())

new_datetime(x = double(), tzone = "")

new_duration(x = double(), units = c("secs", "mins", "hours", "days", "weeks"))

## S3 method for class 'Date'
vec_ptype2(x, y, ...)

## S3 method for class 'POSIXct'
vec_ptype2(x, y, ...)

## S3 method for class 'POSIXlt'
vec_ptype2(x, y, ...)

## S3 method for class 'difftime'
vec_ptype2(x, y, ...)

## S3 method for class 'Date'
vec_cast(x, to, ...)

## S3 method for class 'POSIXct'
vec_cast(x, to, ...)

## S3 method for class 'POSIXlt'
vec_cast(x, to, ...)

## S3 method for class 'difftime'
vec_cast(x, to, ...)

## S3 method for class 'Date'
vec_arith(op, x, y, ...)

## S3 method for class 'POSIXct'
vec_arith(op, x, y, ...)

## S3 method for class 'POSIXlt'
vec_arith(op, x, y, ...)

## S3 method for class 'difftime'
vec_arith(op, x, y, ...)

Arguments

x

A double vector representing the number of days since UNIX epoch for new_date(), number of seconds since UNIX epoch for new_datetime(), and number of units for new_duration().

tzone

Time zone. A character vector of length 1. Either "" for the local time zone, or a value from OlsonNames()

units

Units of duration.

Details

These function help the base Date, POSIXct, and difftime classes fit into the vctrs type system by providing constructors, coercion functions, and casting functions.

Examples

new_date(0)
new_datetime(0, tzone = "UTC")
new_duration(1, "hours")

vctrs

Vector Helpers

v0.3.8
MIT + file LICENSE
Authors
Hadley Wickham [aut], Lionel Henry [aut, cre], Davis Vaughan [aut], data.table team [cph] (Radix sort based on data.table's forder() and their contribution to R's order()), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.