base-round: Rounding and truncating 'timeDate' objects

roundR Documentation

Rounding and truncating 'timeDate' objects

Description

Rounds and truncates objects of class 'timeDate'.

Usage

## S3 method for class 'timeDate'
round(x, digits = c("days", "hours", "mins", "secs", "months", "years"))

## S3 method for class 'timeDate'
trunc(x, units = c("days", "hours", "mins", "secs", "months", "years"),
    ...)

Arguments

digits, units

a character string denoting the date/time units in which the results are desired.

x

an object of class "timeDate".

...

arguments passed to other methods.

Details

The two functions round and trunc allow to round or to truncate "timeDate" objects to the specified unit and return them as "timeDate" objects.

There is an inconsistency in that round uses digits as argument and not units.

From ‘timeDate’ version > 4041.110, the units of rounding are the same as those for round.POSIXt and trunc.POSIXt. Note though that the default for the ‘timeDate’ methods is "days", not "secs".

Value

an object of class "timeDate"

See Also

timeFirstDayInMonth, timeLastDayInMonth, timeFirstDayInQuarter, timeLastDayInQuarter,

timeNthNdayInMonth, timeLastNdayInMonth,

timeNdayOnOrAfter, timeNdayOnOrBefore

Examples

# create a timeDate object
dts <- c("1989-09-28", "2001-01-15", "2004-08-30", "1990-02-09")
tms <- c(  "23:12:55.13",   "10:34:02.23",   "08:30:00.33",   "11:18:23.53")
td <- timeDate(paste(dts, tms), format = "%Y-%m-%d %H:%M:%S",
               zone = "GMT", FinCenter = "GMT")

## round
round(td) # same as round(td, "days")

round(td, "secs")
round(td, "mins")
round(td, "hours")
round(td, "days")
round(td, "months")
round(td, "years")


## truncate
trunc(td) # same as trunc(td, "days")

trunc(td, "secs")
trunc(td, "mins")
trunc(td, "hours")
trunc(td, "days")
trunc(td, "months")
trunc(td, "years")

timeDate documentation built on Oct. 21, 2025, 3 a.m.