Math.Date
Math Group Method for Date/Time Objects

Description

The math group method for Date, POSIXt, and difftime objects.

Usage

## S3 method for class 'Date':
round(x, ...)
## S3 method for class 'Date':
trunc(x, ...)

## S3 method for class 'POSIXt': round(x, units = c("secs", "mins", "hours", "days")) ## S3 method for class 'POSIXt': trunc(x, units = c("secs", "mins", "hours", "days"), ...)

## round, trunc, abs, ceiling, floor, sign, signif ## S3 method for class 'difftime': Math(x, ...)

Arguments

x a Date, POSIXt, or difftime object.
units the unit to truncate or round to.
... additional arguments.
Value
returns an object of class Date, POSIXt, or difftime.
Differences between TIBCO Enterprise Runtime for R and Open-source R
Tests using the trunc.POSIXt(x, units = "secs") in open-source R appear to demonstrate problems with dates after 2038-01-18 19:14:06.
For example:
R> pct <- as.POSIXct(c("2038-01-18 19:14:06.5", "2038-01-18 19:14:07.5")) R> trunc(pct, "secs") [1] "2038-01-18 19:14:06 PST" "2038-01-18 19:14:08 PST" TERR> pct <- as.POSIXct(c("2038-01-18 19:14:06.5", "2038-01-18 19:14:07.5")) TERR> trunc(pct, "secs") {[1] "2038-01-18 19:14:06 PST" "2038-01-18 19:14:07 PST"}
See Also
Math, Date, POSIXt, difftime, Ops.Date, Summary.Date
Examples
## Date
dput(d <- as.Date("2038-01-19") + 0.9)
dput(trunc(d))
dput(round(d))

## POSIXt pct <- as.POSIXct("2038-01-19 13:34:37.5") trunc(pct, "days"); trunc(pct, "hours"); trunc(pct, "mins"); trunc(pct, "secs") round(pct, "days"); round(pct, "hours"); round(pct, "mins"); round(pct, "secs")

## difftime dt <- as.difftime("13:34:37.5") trunc(dt); floor(dt) round(dt); ceiling(dt) abs(dt); sign(dt); signif(dt)

Package base version 6.0.0-69
Package Index