format,CFtime-method {CFtime}R Documentation

Format time elements using format specifiers

Description

Format timestamps using a specific format string, using the specifiers defined for the base::strptime() function, with limitations. The only supported specifiers are ⁠bBdeFhHIjmMpRSTYz%⁠. Modifiers E and O are silently ignored. Other specifiers, including their percent sign, are copied to the output as if they were adorning text.

Usage

## S4 method for signature 'CFtime'
format(x, format)

Arguments

x

CFtime. A CFtime instance whose offsets will be returned as timestamps.

format

character. A character string with strptime format specifiers. If omitted, the most economical format will be used: a full timestamp when time information is available, a date otherwise.

Details

The formatting is largely oblivious to locale. The reason for this is that certain dates in certain calendars are not POSIX-compliant and the system functions necessary for locale information thus do not work consistently. The main exception to this is the (abbreviated) names of months (bB), which could be useful for pretty printing in the local language. For separators and other locale-specific adornments, use local knowledge instead of depending on system locale settings; e.g. specify ⁠%m/%d/%Y⁠ instead of ⁠%D⁠.

Week information, including weekday names, is not supported at all as a "week" is not defined for non-standard CF calendars and not generally useful for climate projection data. If you are working with observed data and want to get pretty week formats, use the as_timestamp() function to generate POSIXct timestamps (observed data generally uses a standard calendar) and then use the base::format() function which supports the full set of specifiers.

Value

A vector of character strings with a properly formatted timestamp. Any format specifiers not recognized or supported will be returned verbatim.

Examples

cf <- CFtime("days since 2020-01-01", "standard", 0:365)
format(cf, "%Y-%b")

# Use system facilities on a standard calendar
format(as_timestamp(cf, asPOSIX = TRUE), "%A, %x")


[Package CFtime version 1.4.0 Index]