iso8601_read: Read ISO 8601 strings into POSIXct, POSIXt

View source: R/iso8601_read.R

iso8601_readR Documentation

Read ISO 8601 strings into POSIXct, POSIXt

Description

Read ISO 8601 strings into POSIXct, POSIXt.

Usage

iso8601_read(x, tz.name = NULL)

Arguments

x

(character) A vector of ISO 8601 strings created with 'iso8601_convert'. Vector contents must be one of dates and times, dates, or times. A mix of more than one type is not supported. A mix of input temporal resolution is supported for date and time data.

tz.name

(character) Time zone name used to override parsing of time zone offset listed in 'x'. See 'OlsonNames()' for valid options.

Details

'iso8601_read' provides a lightweight option for reading ISO 8601 strings created with 'iso8601_convert' into the POSIXct POXIXt class. This function uses regular expressions to extract the orders and time zone offset arguments and passess this info to 'lubridate::parse_date_time' for parsing.

Time zone offsets are parsed "as is", i.e. using Olson Names that do not recognize Day Light Savings time. For example a time zone offset of "+06" is parsed using the Olson Name "Etc/GMT-6". Date times without a time zone offset default to "UTC". Use the argument 'tz.name' to override the input data time zone.

Value

(POSIXct, POSIXt) A vector of POSIXct POSIXt, unless the format is 'YYYY', in which case integer class data is returned.

Examples

# Time zone are automatically parsed
datetimes <- iso8601_read('2012-05-01T13:23:00+05')
attributes(datetimes)

# Time zone defaults to 'UTC' when none is specified
iso8601_read('2012-05-01T13:23:00')

# Vairance of input temporal resolution is supported
iso8601_read(c('2012-05-01T13:45:23+05', '2012-05-01T13:45+05', '2012-05-01T13+05'))

# tz.name overrides input time zone
iso8601_read('2012-05-01T13:45+09:30', tz.name = 'Etc/GMT+4')

## Not run: 
# Multiple time zones are not yet supported
iso8601_read(c('2012-05-01T13-05', '2012-05-01T13-06'))
iso8601_read(c('2012-05-01T13-05', '2012-05-01T13'))

## End(Not run)


EDIorg/dataCleanr documentation built on June 3, 2022, 1:31 a.m.