Learn R Programming

datetimeoffset (version 1.0.0)

from_datetimeoffset: Convert to other datetime objects

Description

We register S3 methods to convert datetimeoffset() objects to other R datetime objects:

Usage

# S3 method for datetimeoffset
as.Date(x, ...)

# S3 method for datetimeoffset as_date(x, ...)

# S3 method for datetimeoffset as.POSIXct(x, tz = mode_tz(x), ..., fill = "")

# S3 method for datetimeoffset as_date_time(x, zone = mode_tz(x), ..., fill = NA_character_)

# S3 method for datetimeoffset as.POSIXlt(x, tz = mode_tz(x), ..., fill = "")

# S3 method for datetimeoffset as_year_month_day(x, ...)

# S3 method for datetimeoffset as_year_month_weekday(x, ...)

# S3 method for datetimeoffset as_iso_year_week_day(x, ...)

# S3 method for datetimeoffset as_year_quarter_day(x, ..., start = NULL)

# S3 method for datetimeoffset as_year_day(x, ...)

# S3 method for datetimeoffset as_naive_time(x, ...)

# S3 method for datetimeoffset as_sys_time( x, ..., ambiguous = "error", nonexistent = "error", fill = NA_character_ )

# S3 method for datetimeoffset as_zoned_time( x, zone = mode_tz(x), ..., ambiguous = "error", nonexistent = "error", fill = NA_character_ )

# S3 method for datetimeoffset as_weekday(x, ...)

Value

A datetime object vector

Arguments

x

A datetimeoffset() object

...

Ignored

tz, zone

What time zone to assume

fill

If timezone and UTC offset info is missing what timezone to assume. See fill_tz().

start

The month to start the fiscal year in. See clock::as_year_quarter_day().

ambiguous

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

nonexistent

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

Details

We register S3 methods for the following:

  • as.Date() and clock::as_date() returns the "local" date as a base::Date() object

  • as.POSIXct() and clock::as_date_time() returns the "local" datetime as a base::POSIXct() object

  • as.POSIXlt() returns the "local" datetime as a base::POSIXlt() object

  • nanotime::as.nanotime() returns the "global" datetime as a nanotime::nanotime() object

  • parttime::as.parttime() returns the "local" datetime as a parttime::parttime() object

  • clock::as_year_month_day() returns a clock::year_month_day() calendar

  • clock::as_year_month_weekday() returns a clock::year_month_weekday() calendar

  • clock::as_iso_year_week_day() returns a clock::iso_year_week_day() calendar

  • clock::as_year_quarter_day() returns a clock::year_quarter_day() calendar

  • clock::as_year_day() returns a clock::year_day() calendar

  • clock::as_naive_time() returns a "clock" naive-time

  • clock::as_sys_time() returns a "clock" sys-time

  • clock::as_zoned_time() returns a "clock" zoned-time

  • clock::as_weekday() returns a clock::weekday() object

Examples

Run this code
  # {base}
  today <- as_datetimeoffset(Sys.Date())
  now <- as_datetimeoffset(Sys.time())

  as.Date(today)
  as.Date(now)
  as.POSIXct(now)
  as.POSIXlt(now)

  # {clock}
  clock::as_date(today)
  clock::as_date_time(now)

  clock::as_year_month_day(now)
  clock::as_year_month_weekday(now)
  clock::as_iso_year_week_day(now)
  clock::as_year_quarter_day(now)
  clock::as_year_day(now)

  clock::as_naive_time(now)
  clock::as_sys_time(now)
  clock::as_zoned_time(now)

  clock::as_weekday(now)

  if (requireNamespace("nanotime")) {
    nanotime::as.nanotime(now)
  }

  if (requireNamespace("parttime")) {
    parttime::as.parttime(now)
  }

Run the code above in your browser using DataLab