consecutive_week: Find the number of weeks between two dates

View source: R/datetime_tools.R

consecutive_weekR Documentation

Find the number of weeks between two dates

Description

Sometimes it's helpful to be able to break down elapsed time in more granular units, like being able to say, "This experiment has been running for 15 weeks". It may also be helpful to say, "It has been 10 calendar weeks since this happened". This function does both of those.

Usage

consecutive_week(from, to, tz = NULL, iso = FALSE)

Arguments

from

(Character or Numeric) A date in the ISO-8601 form "YYYY-MM-DD", or a single number for the year which implies YYYY-01-01.

to

(Character) A date in the ISO-8601 form YYYY-MM-DD.

tz

(Character or NULL) A timezone name such as "Australia/Sydney". Use OlsonNames() for a list of these.

iso

(Logical) If FALSE, returns a naive estimate of weeks elapsed. With R's difftime(), it's the same as dividing the days elapsed by 7. Use round(), ceiling(), or floor() to simplify the result if desired.
If TRUE, returns the number of isoweeks (calendar weeks starting on Mondays) between the two dates. This means that yesterday (Sunday) and today (Monday) fall across two isoweeks even though they're only one day apart.

Value

A numeric vector for the number of weeks elapsed.

Authors

Examples

consecutive_week("2022-01-01", "2022-05-02", iso = FALSE)
#> [1] 17.28571

# Same dates, but they fall over multiple calendar weeks.
consecutive_week("2022-01-01", "2022-05-02", iso = TRUE)
#> [1] 4

# Note that consecutive days can spill over isoweeks.
consecutive_week("2022-05-01", "2022-05-02", iso = TRUE)
#> [1] 2



DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.