numberAsPOSIXct {oce}R Documentation

Convert a Numeric Time to a POSIXct Time

Description

This converts numerical values into POSIXct times. There are many schemes for doing this, with the type parameter being used to select between them. See “Details” for a listing, broken down by scheme.

Usage

numberAsPOSIXct(t, type = "unix", tz = "UTC", leap = TRUE)

Arguments

t

an integer corresponding to a time, in a way that depends on type.

type

character value indicating the time type. The permitted values are "argo", "epic", "excel", "gps", "matlab", "ncep1", "ncep2", "sas", "spss", "unix", and "yearday", the first of these being the default.

tz

a string indicating the time zone, by default "UTC".

leap

a logical value, TRUE by default, that applies only if type is "gps". If leap is TRUE, then the built-in dataset named .leap.seconds is consulted to find of the number of leap seconds between 1980 (when the GPS program started) and the time computed from the other parameters, and the return value is decreased accordingly (see Example 3).

Details

The possible choices for type are as listed below.

Value

A POSIXct() time vector.

Author(s)

Dan Kelley

References

  1. Matlab times: ⁠https://www.mathworks.com/help/matlab/ref/datenum.html⁠

  2. NCEP times: ⁠https://psl.noaa.gov/data/gridded/faq.html⁠

  3. Problem with NCEP times: ⁠https://github.com/dankelley/oce/issues/738⁠

  4. EPIC times: software and manuals at ⁠https://www.pmel.noaa.gov/epic/download/index.html#epslib⁠; see also Denbo, Donald W., and Nancy N. Soreide. “EPIC.” Oceanography 9 (1996). doi:10.5670/oceanog.1996.10

  5. VMS times: https://en.wikipedia.org/wiki/Epoch_(computing)

  6. GPS times: https://www.labsat.co.uk/index.php/en/gps-time-calculator

See Also

Other things related to time: ctimeToSeconds(), julianCenturyAnomaly(), julianDay(), numberAsHMS(), secondsToCtime(), unabbreviateYear()

Other things related to time: ctimeToSeconds(), julianCenturyAnomaly(), julianDay(), numberAsHMS(), secondsToCtime(), unabbreviateYear()

Examples

# Example 1. default (unix)
numberAsPOSIXct(0)

# Example 2. Matlab
numberAsPOSIXct(1, type = "matlab")

# Example 3. GPS with default week rollover or with no rollover (Canada Day, year 2010)
numberAsPOSIXct(cbind(566, 345615), type = "gps")
numberAsPOSIXct(cbind(566, 345615, 1), type = "gps")
numberAsPOSIXct(cbind(1024 + 566, 345615, 0), type = "gps")
# Show how to deal with leap seconds (15 of them, in this case)
sum(as.POSIXct("1980-01-01") < .leap.seconds & .leap.seconds <= as.POSIXct("2010-07-01"))
-15 + numberAsPOSIXct(cbind(1024 + 566, 345615, 0), type = "gps", leap = FALSE)

# Example 4. yearday
numberAsPOSIXct(cbind(2013, 1), type = "yearday") # start of 2013

# Example 5. Epic time, one hour into Canada Day of year 2018. In computing the
# Julian day, note that this starts at noon.
jd <- julianDay(as.POSIXct("2018-07-01 12:00:00", tz = "UTC"))
numberAsPOSIXct(cbind(jd, 1e3 * 1 * 3600), type = "epic", tz = "UTC")

# Example 6. Julian day, note that this starts at noon.
jd <- julianDay(as.POSIXct("2018-07-01 12:00:00", tz = "UTC"))
numberAsPOSIXct(cbind(jd, 1e3 * 1 * 3600), type = "epic", tz = "UTC")


[Package oce version 1.8-2 Index]