Learn R Programming

clock (version 0.7.1)

year_week_day: Calendar: year-week-day

Description

year_week_day() constructs a calendar from the year, week number, week day, and the start of the week.

Using start = clock_weekdays$monday represents the ISO week calendar and is equivalent to using iso_year_week_day().

Using start = clock_weekdays$sunday is how Epidemiologists encode their week-based data.

Usage

year_week_day(
  year,
  week = NULL,
  day = NULL,
  hour = NULL,
  minute = NULL,
  second = NULL,
  subsecond = NULL,
  ...,
  start = NULL,
  subsecond_precision = NULL
)

Value

A year-week-day calendar vector.

Arguments

year

[integer]

The year. Values [-32767, 32767] are generally allowed.

week

[integer / "last" / NULL]

The week. Values [1, 53] are allowed.

If "last", then the last week of the year is returned.

day

[integer / NULL]

The day of the week. Values [1, 7] are allowed, with 1 = start of week and 7 = end of week, in accordance with start.

hour

[integer / NULL]

The hour. Values [0, 23] are allowed.

minute

[integer / NULL]

The minute. Values [0, 59] are allowed.

second

[integer / NULL]

The second. Values [0, 59] are allowed.

subsecond

[integer / NULL]

The subsecond. If specified, subsecond_precision must also be specified to determine how to interpret the subsecond.

If using milliseconds, values [0, 999] are allowed.

If using microseconds, values [0, 999999] are allowed.

If using nanoseconds, values [0, 999999999] are allowed.

...

These dots are for future extensions and must be empty.

start

[integer(1) / NULL]

The day to consider the start of the week. 1 = Sunday and 7 = Saturday.

Use clock_weekdays for a readable way to specify the start.

If NULL, a start of Sunday will be used.

subsecond_precision

[character(1) / NULL]

The precision to interpret subsecond as. One of: "millisecond", "microsecond", or "nanosecond".

Details

Fields are recycled against each other using tidyverse recycling rules.

Fields are collected in order until the first NULL field is located. No fields after the first NULL field are used.

Examples

Run this code
# Year-week
x <- year_week_day(2019:2025, "last")
x

# Start the week on Monday
y <- year_week_day(2019:2025, "last", start = clock_weekdays$monday)
y

# Last days of the year
as_year_month_day(set_day(x, 7))
as_year_month_day(set_day(y, 7))

Run the code above in your browser using DataLab