Title: | Parse 'YMD' Format Number or String to Date |
---|---|
Description: | Convert 'YMD' format number or string to Date efficiently, using Rust's standard library. It also provides helper functions to handle Date, e.g., quick finding the beginning or end of the given period, adding months to Date, etc. |
Authors: | Xianying Tan [aut, cre] , Hiroaki Yutani [ctb] (<https://orcid.org/0000-0002-3385-7233>, configure, configure.win, tools/configure.R), The authors of the dependency Rust crates [ctb] (see inst/AUTHORS file for details) |
Maintainer: | Xianying Tan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.3 |
Built: | 2024-11-06 04:56:16 UTC |
Source: | https://github.com/shrektan/ymd |
Each of bop
and eop
contains a list of functions, whose names all
consist of two letters, the first of which stands for last, this, next
while the second stands for year, quarter, month, week.
For example, eop$ty()
means "the ending of period of this year"
and bop$lm()
means "the beginning of period of last month".
All functions' signatures are the same, with only one argument
x
, which could be a Date
or values that can be converted to Date
via ymd()
.
bop$ty(as.Date("2021-03-02")) ## supports 'YMD' formatted integer or string bop$ty(210302) eop$tm(200201)
bop$ty(as.Date("2021-03-02")) ## supports 'YMD' formatted integer or string bop$ty(210302) eop$tm(200201)
These date helper functions provide the similar functionalities like in data.table
or
lubridate
package. They are implemented by the Rust Lang's standard library and very
fast.
year(ref_date) month(ref_date) quarter(ref_date) isoweek(ref_date) isowday(ref_date) wday(ref_date) mday(ref_date) yday(ref_date)
year(ref_date) month(ref_date) quarter(ref_date) isoweek(ref_date) isowday(ref_date) wday(ref_date) mday(ref_date) yday(ref_date)
ref_date |
a Date vector. It will try to convert the input to date via |
year, month, quarter: get the year, month, quarter part
yday: the day of year
mday: the day of month
wday: the day of the week (Sunday is 1)
isoweek: ISO 8601 week
isowday: the day of week (ISO 8601 weekday number, Monday is 1)
an integer vector
ISO week day, https://en.wikipedia.org/wiki/ISO_week_date ISO 8601, https://en.wikipedia.org/wiki/ISO_8601
year(210205) month(210205) quarter(210205) yday(210205) mday(210205) wday(210117) isowday(210117) isoweek(210101)
year(210205) month(210205) quarter(210205) yday(210205) mday(210205) wday(210117) isowday(210117) isoweek(210101)
Calculate the date before / after months
edate(ref_date, months)
edate(ref_date, months)
ref_date |
a Date vector |
months |
the number of months that's added to |
The function name is the same as the Excel function EDATE()
and
does the same. It returns the date that is the indicated number of months
before or after the ref date.
edate(as.Date("2020-01-31"), 1) ## supports 'YMD' formatted integer or string edate(200131, 1) edate(200229, -12)
edate(as.Date("2020-01-31"), 1) ## supports 'YMD' formatted integer or string edate(200131, 1) edate(200229, -12)
Transform integer or strings vectors in 'YMD' format to Date objects. It intends to only support limited formats (no separator or one of '.', ' ', '-' and '/' separators). See the possible formats in examples.
ymd(x, ...)
ymd(x, ...)
x |
An integer or string vector in 'YMD' format. Double values without the decimal part are allowed. |
... |
The same as |
A Date object. When the parse fails for certain input,
the value returned would be NA
, silently.
ymd(c(210326, 19981225)) ymd(c("2020/1/8", "20 1 7", "1998.7.1", "1990-02-03")) ymd(210420, 180322)
ymd(c(210326, 19981225)) ymd(c("2020/1/8", "20 1 7", "1998.7.1", "1990-02-03")) ymd(210420, 180322)