int_duration: Compute the duration of an 'Interval' object

View source: R/int_duration.R

int_durationR Documentation

Compute the duration of an Interval object

Description

[Maturing]

int_duration() computes the duration of an Interval object

Usage

int_duration(int = NULL)

Arguments

int

An Interval vector.

Value

A Duration vector.

See Also

Other Interval functions: int_mean(), int_overlap()

Examples

lubridate::interval(
  lubridate::ymd_hms("2023-01-01 22:00:01", tz = "UTC"),
  lubridate::ymd_hms("2023-01-02 02:00:01", tz = "UTC"),
  tzone = "UTC"
) |>
  int_duration()
#> [1] "14400s (~4 hours)" # Expected

lubridate::interval(
  lubridate::ymd_hms("2023-01-01 22:00:01", tz = "UTC"),
  lubridate::ymd_hms("2023-01-02 02:00:01", tz = "UTC"),
  tzone = "UTC"
) |>
  int_duration() |>
  lubridate::as.period()
#> [1] "4H 0M 0S" # Expected

c(
  lubridate::interval(
    lubridate::ymd_hms("2023-01-01 22:00:01", tz = "UTC"),
    lubridate::ymd_hms("2023-01-02 02:00:01", tz = "UTC"),
    tzone = "UTC"
  ),
  lubridate::interval(
    lubridate::ymd_hms("1990-01-01 06:00:00", tz = "UTC"),
    lubridate::ymd_hms("1990-01-01 12:00:00", tz = "UTC"),
    tzone = "UTC"
  )
) |>
  int_duration()
#> [1] "14400s (~4 hours)" "21600s (~6 hours)" # Expected

gipso/lubritime documentation built on April 17, 2025, 12:03 p.m.