theRefdate provides simple and fast date manipulation
functions operating on character strings. By default the strings have
the format "DD.MM.YYYY" (flavour "dmy"),
exactly as in version 1.0.0. The package does not convert dates to a
date class, which keeps it simple and fast.
A flavour is the date format the package works with. Three flavours exist:
| flavour | format | example |
|---|---|---|
"dmy" |
DD.MM.YYYY |
"02.02.2002" |
"iso" |
YYYY-MM-DD |
"2002-02-02" |
"iso_basic" |
YYYYMMDD |
"20020202" |
Without any setting the flavour is "dmy", and every
function returns the same results as in version 1.0.0.
flavour() returns the active flavour:
setFlavour() selects another flavour for the whole R
session. Call it once, at the start of a session or in the
initialization of the code that uses the package. Calling it later with
a different flavour gives a warning, because two formats in one session
usually indicate a mistake. The old identifiers "LP" (=
"dmy") and "VK" (= "iso") are
still accepted.
setFlavour("iso")
jahr("2002-02-02")
#> [1] 2002
dateAddMonths("2002-02-02", 11)
#> [1] "2003-01-02"
setFlavour("dmy")
#> Warning: theRefdate: Flavour wechselt von 'iso' auf 'dmy' innerhalb der SitzungFor a single call the argument format overrides the
session flavour:
Input that is not a date in the active format stops with an error
that names the argument, its class and value, and the expected format.
This includes NA and the empty string, for which version
1.0.0 returned NA:
jahr(NA_character_)
#> Error: theRefdate: Argument 'datumstring' (Klasse 'character', Wert 'NA'): enthaelt keine Zahl, erwartet Format TT.MM.JJJJ
jahr("2002-02-02") # ISO date while the flavour is "dmy"
#> Warning in jahr("2002-02-02"): NAs durch Umwandlung erzeugt
#> Error: theRefdate: Argument 'datumstring' (Klasse 'character', Wert '2002-02-02'): enthaelt keine Zahl, erwartet Format TT.MM.JJJJComputes the difference between two dates. Returns a list with four
elements: diffJ (years), diffM (months),
diffDauer (duration as fraction of years),
diffDauerM (total months):
Adds or subtracts whole months from a date. The day is left unchanged and the year is written with four digits: