Learn R Programming

datetimeoffset (version 1.0.0)

mode_tz: Get most common time zone

Description

'mode_tz()' gets the most common time zone in the datetime object. If a tie we use the time zone used first. Intended for use when coercing from a datetime object that supports multiple heterogeneous time zones to a datetime object that only supports one time zone

Usage

mode_tz(x, ...)

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

# S3 method for default mode_tz(x, ...)

Value

Timezone string

Arguments

x

A datetime object.

...

Ignored

tz

A timezone string to use for missing time zones. "" will be treated as equivalent to Sys.timezone().

Examples

Run this code
  dt <- as_datetimeoffset(Sys.time())
  print(mode_tz(dt))
  if (all(c("America/Los_Angeles", "America/New_York") %in% OlsonNames())) {
    dt <- as_datetimeoffset("2020-01-01",
                             tz = c("America/Los_Angeles", "America/New_York"))
    print(mode_tz(dt))

    print(Sys.timezone()) # timezone to be used for missing time zones
    dt <- as_datetimeoffset("2020-01-01",
                             tz = c("America/New_York", NA_character_, NA_character_))
    print(mode_tz(dt))
  }

Run the code above in your browser using DataLab