Learn R Programming

calcal (version 1.0.0)

granularity_names: Canonical granularities

Description

granularities() will return a character vector of canonical granularity names for the relevant calendar. These are the granularities used to define dates on the calendar. granularity() will return a vector of numerical values for a given canonical granularity.

Usage

granularity_names(calendar)

granularity(date, granularity)

Value

A character vector of granularity names or a vector of numerical values for the specified granularity.

Arguments

calendar

A calcal object defining a calendar.

date

A date vector on some calendar

granularity

A character string indicating the granularity to extract

See Also

week_of_year for some non-canonical granularities.

Examples

Run this code
granularity_names(cal_iso)
granularity_names(cal_gregorian)
date_iso <- new_date(year = 2025, week = 23, day = 2, calendar = cal_iso)
granularity(date_iso, "week")
date_gregorian <- new_date(year = 2025, month = 1, day = 1, calendar = cal_gregorian)
granularity(date_gregorian, "month")

Run the code above in your browser using DataLab