timeDate: Create 'timeDate' objects from scratch

timeDateR Documentation

Create 'timeDate' objects from scratch

Description

Create a "timeDate" object from scratch from a character vector or other suitable objects.

Usage

timeDate(charvec, format = NULL, zone = "", FinCenter = "", ...)

## S4 method for signature 'character'
timeDate(charvec, format = NULL, zone = "", FinCenter = "", 
         dst_gap = "+")

strptimeDate(x, format = whichFormat(x), tz = "")

Arguments

charvec

a character string or vector of dates and times.

format

the format specification of the input character vector.

tz

a character with the location of the financial center named as "continent/city", or short "city".

zone

the time zone or financial center where the data were recorded.

x

a character string or vector of dates and times.

FinCenter

a character with the location of the financial center named as "continent/city".

dst_gap

a character string specifying what to do with non-existent times falling in a DST gap: add an hour ("+"), subtract an hour ("-"), set to NA ("NA"), or ignore (""). When the ‘ignore’ option is used the code to check for this kind of faulty times is skipped and the result will be equivalent to "+" or "-" but which one is not defined. This could be useful when you are certain that there are no times in DST gaps or don't care how they are dealt with.

...

further arguments for methods.

Details

timeDate creates objects from class "timeDate" from character vectors, objects from several date/time classes, and other suitable objects.. It is an S4 generic function and this page describes the methods defined in package timeDate, see section ‘Methods’.

Note that zone is the time zone of the input, while FinCenter is the ‘current’ time zone, typically but not necessarilly where the code is run. To change one or both of these time zones of an existing "timeDate" object, call timeDate() on it, see the method for charvec = "timeDate" in section ‘Methods’.

strptimeDate is a wrapper of timeDate, suitable when zone and FinCenter are the same, It has the same arguments as strptime. If format is missing it tries to deduce it. If tz is missing it sets it to the value of the Rmetrics option "myFinCenter".

Value

an object of class "timeDate"

Methods

The following methods for timeDate are defined in package timeDate.

signature(charvec = "ANY")

Converts charvec to character and calls timeDate on the result.

signature(charvec = "character")

...

signature(charvec = "Date")

...

signature(charvec = "missing")

Returns the current time as "timeDate" object.

signature(charvec = "numeric")

...

signature(charvec = "POSIXt")

...

signature(charvec = "timeDate")

Changes the time zone and/or financial center of charvec to the requested ones. If zone is missing or equal to the empty string, just changes the financial center.

Examples

## timeDate -

   # Character Vector Strings:
   dts = c("1989-09-28", "2001-01-15", "2004-08-30", "1990-02-09")
   tms = c(  "23:12:55",   "10:34:02",   "08:30:00",   "11:18:23")

   dts; tms

   t1 <- timeDate(dts, format = "%Y-%m-%d", FinCenter = "GMT" )
   t1
   
   stopifnot(identical(t1, timeDate(dts, FinC = "GMT"))) # auto-format
   
   timeDate(dts, format = "%Y-%m-%d", FinCenter = "Europe/Zurich")
   
   timeDate(paste(dts, tms), format = "%Y-%m-%d %H:%M:%S",
        zone = "GMT", FinCenter = "GMT")
   
   timeDate(paste(dts, tms), 
        zone = "Europe/Zurich", FinCenter = "Europe/Zurich")
   
   timeDate(paste(dts, tms), format = "%Y-%m-%d %H:%M:%S",
        zone = "GMT", FinCenter = "Europe/Zurich")

   ## Non Standard Format:
   timeDate(paste(20:31, "03.2005", sep="."), format = "%d.%m.%Y")

   ## Note, ISO and American Formats are Auto-Detected:
   timeDate("2004-12-31", FinCenter = "GMT")
   timeDate("12/11/2004", FinCenter = "GMT")
   timeDate("1/31/2004") # auto-detect American format

   ## From POSIX?t, and using NAs
   ## lsec <- as.POSIXlt(.leap.seconds) ; lsec[c(2,4:6)] <- NA
   ## timeDate(lsec)

   ## dtms <- paste(dts,tms)
   ## dtms[2:3] <- NA
   ## timeDate(dtms, FinCenter = "Europe/Zurich") # but in GMT

   
   
   


timeDate documentation built on Jan. 7, 2023, 5:30 p.m.