Generate a time range
Description
Generate a time range
Usage
pl$time_range(
start = NULL,
end = NULL,
interval = "1h",
...,
closed = c("both", "left", "none", "right")
)
Arguments
start
|
Lower bound of the time range. If omitted, defaults to
00:00:00.000 .
|
end
|
Upper bound of the time range. If omitted, defaults to
23:59:59.999
|
interval
|
Interval of the range periods, specified as a difftime or using the Polars duration string language (see details). |
…
|
These dots are for future extensions and must be empty. |
closed
|
Define which sides of the range are closed (inclusive). One of the
following: “both” (default), “left” ,
“right” , “none” .
|
Value
A polars expression
Polars duration string language
Polars duration string language is a simple representation of durations. It is used in many Polars functions that accept durations.
It has the following format:
- 1ns (1 nanosecond)
- 1us (1 microsecond)
- 1ms (1 millisecond)
- 1s (1 second)
- 1m (1 minute)
- 1h (1 hour)
- 1d (1 calendar day)
- 1w (1 calendar week)
- 1mo (1 calendar month)
- 1q (1 calendar quarter)
- 1y (1 calendar year)
Or combine them: “3d12h4m25s”
# 3 days, 12 hours, 4
minutes, and 25 seconds
By "calendar day", we mean the corresponding time on the next day (which may not be 24 hours, due to daylight savings). Similarly for "calendar week", "calendar month", "calendar quarter", and "calendar year".
Examples
library("polars")
pl$select(
time = pl$time_range(
start = hms::parse_hms("14:00:00"),
interval = as.difftime("3:15:00")
)
)
#> shape: (4, 1)
#> ┌──────────┐
#> │ time │
#> │ --- │
#> │ time │
#> ╞══════════╡
#> │ 14:00:00 │
#> │ 17:15:00 │
#> │ 20:30:00 │
#> │ 23:45:00 │
#> └──────────┘