A Toolkit for Year-Quarter, Year-Month and Year-Isoweek Dates

S3 classes and methods to create and work with year-quarter, year-month and year-isoweek vectors. Basic arithmetic operations (such as adding and subtracting) are supported, as well as formatting and converting to and from standard R date types.


CRAN status lifecycle Travis build status Coverage status

A Toolkit for Year-Quarter, Year-Month and Year-Isoweek Dates

S3 classes and methods to create and work with year-quarter and year-month vectors. Basic arithmetic operations (such as adding and subtracting) are supported, as well as formatting and converting to and from standard R Date types.

Installation

Install the release version of dint from CRAN:

install.packages("dint")

Or install the development version from GitHub with:

devtools::install_github("s-fleck/dint")

Example

library(dint)
 
# creation
q <- date_yq(2014, 4)
m <- as_date_ym(201412)
w <- as_date_yw(as.Date("2017-01-01"))
 
# printing
print(q)
#> [1] "2014-Q4"
print(m)
#> [1] "2014-M12"
print(w)  # isoweeks do not follow calender years!
#> [1] "2016-W52"
 
# arithmetic operations
# quarters
q
#> [1] "2014-Q4"
q + 1
#> [1] "2015-Q1"
seq(q -2, q + 2)
#> [1] "2014-Q2" "2014-Q3" "2014-Q4" "2015-Q1" "2015-Q2"
 
 
# months
m
#> [1] "2014-M12"
m + 1
#> [1] "2015-M01"
seq(m -2, m + 2)
#> [1] "2014-M10" "2014-M11" "2014-M12" "2015-M01" "2015-M02"
 
 
# formatting
format(q)
#> [1] "2014-Q4"
format(q, "%Y.%q")
#> [1] "2014.4"
format(q, "%y.%q")
#> [1] "14.4"
format(m)
#> [1] "2014-M12"
 
 
# get start and end of period
last_of_quarter(q)
#> [1] "2014-12-31"
first_of_quarter(q)
#> [1] "2014-10-01"
first_of_month(Sys.Date())
#> [1] "2018-09-01"
first_of_isoweek(w)
#> [1] "2016-12-26"
last_of_isoweek(w)
#> [1] "2017-01-01"

News

dint 2.0.0

  • breaking: formatting date_xx objects now uses placeholders similar to base::strptime() (e.g %Y, %m, %q, etc...) instead of presets. The new implementation is also noticably faster than the old.
  • breaking: all first_day_of_*() and format_date_y*() functions now have shorter names: first_of_*() and format_y*(). The original names will still work until the next release but give a deprecation warning.
  • Added support for c(), min(), max(), range()
  • You can now direclty supply a numeric year to first_of_year() and last_of_year() (e.g. first_of_year(2018))
  • added date_yw for storing isoweeks and modified existing funtions to accomodate for them.
  • added [ method for date_xx objects that preserves class attribute when subsetting
  • %y+% / %y-% can add/subtract years from date_xx objects
  • added the predicates, is_first_of_quarter(), is_last_of_quarter(), and is_quarter_bounds().
  • seq() methods now support a by argument

dint 1.0.0

  • First stable version

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("dint")

2.1.0 by Stefan Fleck, 19 days ago


https://github.com/s-fleck/dint


Report a bug at https://github.com/s-fleck/dint/issues


Browse source code at https://github.com/cran/dint


Authors: Stefan Fleck [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests covr, ggplot2, knitr, lubridate, rmarkdown, scales, testthat, zoo


See at CRAN