timechange (version 0.0.2)

time_update: Update components of a date-time object

Description

Update components of a date-time object

Usage

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)
)

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.

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.

Examples

Run this code
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")

Run the code above in your browser using DataLab