time_update: Update components of a date-time object

Description Usage Arguments Value Examples

View source: R/update.R

Description

Update components of a date-time object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
time_update(
  time,
  updates = NULL,
  year = NULL,
  month = NULL,
  yday = NULL,
  day = NULL,
  mday = NULL,
  wday = NULL,
  hour = NULL,
  minute = NULL,
  second = NULL,
  tz = NULL,
  roll_month = "last",
  roll_dst = "boundary",
  week_start = getOption("timechange.week_start", 1)
)

Arguments

time

a date-time object

updates

a named list of components

year, month, yday, wday, mday, day, hour, minute, second

components of the date-time to be updated. day is equivalent to mday. All components except second will be converted to integer.

tz

time zone component (a singleton character vector)

roll_month, roll_dst

See time_add().

week_start

first day of the week (default is 1, Monday). Set timechange.week_start option to change this globally.

Value

A date-time with the requested elements updated. Retain its original class unless the original class is Date and at least one of the hour, minute, second or tz is supplied, in which case a POSIXct object is returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
date <- as.Date("2009-02-10")
time_update(date, year = 2010, month = 1, mday = 1)
time_update(date, year = 2010, month = 13, mday = 1)
time_update(date, minute = 10, second = 3)
time_update(date, minute = 10, second = 3, tz = "America/New_York")

time <- as.POSIXct("2015-02-03 01:02:03", tz = "America/New_York")
time_update(time, year = 2016, yday = 10)
time_update(time, year = 2016, yday = 10, tz = "Europe/Amsterdam")
time_update(time, second = 30,  tz = "America/New_York")

timechange documentation built on Jan. 13, 2021, 5:19 p.m.