setters {datetimeoffset}R Documentation

Set datetime components

Description

Setter methods for datetimeoffset() objects.

Usage

## S3 method for class 'datetimeoffset'
set_year(x, value, ..., na_set = FALSE)

## S3 method for class 'datetimeoffset'
set_month(x, value, ..., na_set = FALSE)

## S3 method for class 'datetimeoffset'
set_day(x, value, ..., na_set = FALSE)

## S3 method for class 'datetimeoffset'
set_hour(x, value, ..., na_set = FALSE)

## S3 method for class 'datetimeoffset'
set_minute(x, value, ..., na_set = FALSE)

## S3 method for class 'datetimeoffset'
set_second(x, value, ..., na_set = FALSE)

## S3 method for class 'datetimeoffset'
set_nanosecond(x, value, ..., na_set = FALSE, digits = NULL)

set_subsecond_digits(x, value, ...)

## S3 method for class 'datetimeoffset'
set_subsecond_digits(x, value, ..., na_set = FALSE)

set_hour_offset(x, value, ...)

## S3 method for class 'datetimeoffset'
set_hour_offset(x, value, ..., na_set = FALSE)

set_minute_offset(x, value, ...)

## S3 method for class 'datetimeoffset'
set_minute_offset(x, value, ..., na_set = FALSE)

set_tz(x, value, ...)

## S3 method for class 'datetimeoffset'
set_tz(x, value, ..., na_set = FALSE)

## S3 method for class 'clock_zoned_time'
set_tz(x, value, ..., nonexistent = "error", ambiguous = "error")

## Default S3 method:
set_tz(x, value, ...)

Arguments

x

A datetime object.

value

The replacement value. For set_day() this can also be "last".

...

Currently ignored.

na_set

If TRUE set component for NA datetimes (making them no longer NA)

digits

If NULL do not update the subsecond_digits field. Otherwise an integer vector (1L through 9L or NA_integer_) to update the subsecond_digits field with.

nonexistent

What to do when the "clock time" in the new time zone doesn't exist. See clock::as_zoned_time.clock_naive_time().

ambiguous

What to do when the "clock time" in the new time zone is ambiguous. See clock::as_zoned_time.clock_naive_time().

Details

We implement datetimeoffset() support for the following S3 methods from clock:

We also implemented new S3 setter methods:

We also implement datetimeoffset() support for the following S4 methods from lubridate:

Value

A datetime object.

Examples

library("clock")
dt <- NA_datetimeoffset_
dt <- set_year(dt, 1918L, na_set = TRUE)
dt <- set_month(dt, 11L)
dt <- set_day(dt, 11L)
dt <- set_hour(dt, 11L)
dt <- set_minute(dt, 11L)
dt <- set_second(dt, 11L)
dt <- set_nanosecond(dt, 123456789L)
dt <- set_subsecond_digits(dt, 4L)
dt <- set_hour_offset(dt, 0L)
dt <- set_minute_offset(dt, 0L)
dt <- set_tz(dt, "Europe/Paris")
format(dt)

if (require("lubridate")) {
  dt <- datetimeoffset(0L)
  year(dt) <- 1918L
  month(dt) <- 11L
  day(dt) <- 11L
  hour(dt) <- 11L
  minute(dt) <- 11L
  second(dt) <- 11L
  if (packageVersion("lubridate") > '1.8.0' &&
      "Europe/Paris" %in% OlsonNames()) {
    tz(dt) <- "Europe/Paris"
  }
  format(dt)
}

[Package datetimeoffset version 0.3.1 Index]