vec_cast.partial_time.character: Coerce character date representations to parttime objects

View source: R/class_partial_time_coercion.R

vec_cast.partial_time.characterR Documentation

Coerce character date representations to parttime objects

Description

Coerce character date representations to parttime objects

Usage

## S3 method for class 'partial_time.character'
vec_cast(x, to, ..., format = parse_iso8601_datetime, on.na = warning)

Arguments

x

Vectors to cast.

to

Type to cast to. If NULL, x will be returned as is.

...

Additional arguments passed to format if a function is provided.

format

a function or character value. If a function, it should accept a character vector and return a matrix of parttime components. If a character it should provide a regular exprssion which contains capture groups for each of the parttime components. See parse_to_parttime_matrix's regex parameter for more details.

on.na

a function used to signal a condition for new NA values introduced by coercion, a character value among "error", "warning" or "suppress" (for silencing messages) or NULL equivalent to "suppress".

Value

A partial_time vector

Examples

dates <- c(
  NA,
  "2001",
  "2002-01-01",
  "2004-245", # yearday
  "2005-W13", # yearweek
  "2006-W02-5", # yearweek + weekday
  "2007-10-01T08",
  "2008-09-20T08:35",
  "2009-08-12T08:35.048", # fractional minute
  "2010-07-22T08:35:32",
  "2011-06-13T08:35:32.123", # fractional second
  "2012-05-23T08:35:32.123Z", # Zulu time
  "2013-04-14T08:35:32.123+05", # time offset from GMT
  "2014-03-24T08:35:32.123+05:30", # time offset with min from GMT
  "20150101T083532.123+0530" # condensed form
)

as.parttime(dates)


parttime documentation built on May 29, 2024, 6:25 a.m.