package timere
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=777b10b706165e3b28a2e3893305dfe156493b152bbda407679a551878818c79
doc/timere/Timere/index.html
Module Timere
Source
This is the core type of Timere used to encode computation over time.
The following documentation may call value of type t
"a Timere object", or "timere".
Printing exception
Basic constructors
Entire interval that Timere can handle, i.e. [0000 Jan 01 14:00:00 +00:00:00, 9999 Dec 31 09:59:58 +00:00:00)
year_ranges l
is a shorthand for pattern ~year_ranges:l ()
month_ranges l
is a shorthand for pattern ~month_ranges:l ()
day_ranges l
is a shorthand for pattern ~month_day_ranges:l ()
weekday_ranges l
is a shorthand for pattern ~weekday_ranges:l ()
hour_ranges l
is a shorthand for pattern ~hour_ranges:l ()
minute_ranges l
is a shorthand for pattern ~minute_ranges:l ()
second_ranges l
is a shorthand for pattern ~second_ranges:l ()
val pattern :
?years:int list ->
?year_ranges:int range list ->
?months:month list ->
?month_ranges:month range list ->
?days:int list ->
?day_ranges:int range list ->
?weekdays:weekday list ->
?weekday_ranges:weekday range list ->
?hours:int list ->
?hour_ranges:int range list ->
?minutes:int list ->
?minute_ranges:int range list ->
?seconds:int list ->
?second_ranges:int range list ->
unit ->
t
Pattern matches over date times.
A pattern p
matches date time dt
if
(dt.year is in p.years or p.year_ranges) && (dt.month is in p.months or p.month_ranges) && (dt.month_day is in p.month_days or p.month_day_ranges) && (dt.weekday is in p.weekdays or p.weekday_ranges) && (dt.hour is in p.hours or p.hour_ranges) && (dt.minute is in p.minutes or p.minute_ranges) && (dt.second is in p.seconds or p.second_ranges)
Empty pattern levels are treated as wildcard, e.g. if p.years
and p.year_ranges
are both empty, then (dt.year is in p.years or p.year_ranges)
is true
.
nth_weekday_of_month n wday
picks the nth weekday of all months, where 1 <= n && n <= 5
Algebraic operations
Negation of timere.
not t
is equivalent to all the intervals not included in t
.
Duration
Time zone
with_tz tz t
changes the time zone to evaluate t
in to tz
Date time and timestamps
timestamps l
skip_invalid
defaults to false
timestamps s
skip_invalid
defaults to false
Intervals
Explicit
intervals l
skip_invalid
defaults to false
interval_seq s
skip_invalid
defaults to false
sorted_intervals l
skip_invalid
defaults to false
sorted_interval_seq s
skip_invalid
defaults to false
Pattern matching
Pattern matching intervals are designed to handle intervals where start and end points follow some pattern, but cannot be captured by pattern
efficiently, e.g. you cannot represent "5:30pm to 6:11pm" via a single pattern
val make_points :
?tz:Time_zone.t ->
?tz_offset_s:int ->
?year:int ->
?month:month ->
?day:int ->
?weekday:weekday ->
?hour:int ->
?minute:int ->
second:int ->
unit ->
points option
make_points
call must be exactly one of the following forms (ignoring tz
and tz_offset_s
which are optional in all cases)
make_points ~year:_ ~month:_ ~day:_ ~hour:_ ~minute:_ ~second:_ () make_points ~month:_ ~day:_ ~hour:_ ~minute:_ ~second:_ () make_points ~day:_ ~hour:_ ~minute:_ ~second:_ () make_points ~weekday:_ ~hour:_ ~minute:_ ~second:_ () make_points ~hour:_ ~minute:_ ~second:_ () make_points ~minute:_ ~second:_ () make_points ~second:_ ()
returns Error
otherwise
val make_points_exn :
?tz:Time_zone.t ->
?tz_offset_s:int ->
?year:int ->
?month:month ->
?day:int ->
?weekday:weekday ->
?hour:int ->
?minute:int ->
second:int ->
unit ->
points
bounded_intervals mode bound p1 p2
for each point x
matched by p1
, then for each earliest point y
matched by p2
such that x < y && y - x <= bound
- if
mode = `Whole
, yields (x, y) - if
mode = `Snd
, yields (y, y + 1)
Examples:
bounded_intervals `Whole (Duration.make ~days:1 ())
(make_points ~hour:13 ~minute:0 ~second:0 ()) (* p1 *)
(make_points ~hour:14 ~minute:0 ~second:0 ()) (* p2 *)
yields all the "1pm to 2pm" intervals, since at each "1pm" mark represented by p1
, searching forward up to 24 hour period, we can find a "2pm" mark in p2
bounded_intervals `Whole (Duration.make ~days:1 ())
(make_points ~month:`Feb ~day:10 ~hour:13 ~minute:0 ~second:0 ()) (* p1 *)
(make_points ~hour:14 ~minute:0 ~second:0 ()) (* p2 *)
yields all the "Feb 10th 1pm to 2pm" intervals (or specifically "Feb 10th 1pm to Feb 10th 2pm")
bounded_intervals `Whole (Duration.make ~days:1 ())
(make_points ~month:`Feb ~day:10 ~hour:23 ~minute:0 ~second:0 ()) (* p1 *)
(make_points ~hour:3 ~minute:0 ~second:0 ()) (* p2 *)
yields all the "Feb 10th 11pm to 3am" intervals (or specifically "Feb 10th 11pm to Feb 11th 3am")
For example, make_points_exn ~hour:3 ~minute:0 ~second:0 ()
has a lower precision than make_points_exn ~day:10 ~hour:12 ~minute:30 ~second:0 ()
Hour minute second intervals
Convenience wrappers around points
and bounded_intervals
Same as hms_intervals_exc ...
with end point increased by one second
Same as bounded_intervals ...
with bound fixed to Duration.make ~days:1 ()
Chunking
type chunking = [
| `Disjoint_intervals
| `By_duration of Duration.t
| `By_duration_drop_partial of Duration.t
| `At_year_boundary
| `At_month_boundary
]
Ways to chunk/slice time intervals for the selector.
`Disjoint_intervals
gives a sequence of disjoint intervals to the selector, specifically they are in ascending order, non-overlapping, non-connecting, and unique`By_duration
slices in the fixed size specified by the duration. Partial chunks (chunks less than the fixed size) are preserved.`By_duration_drop_partial
slices in the fixed size specified by the duration. Partial chunks (chunks less than the fixed size) are discarded.`At_year_boundary
slices at the year boundary (e.g.2021 Jan 1st 00:00:00
)`At_month_boundary
slices at the month boundary (e.g.Aug 1st 00:00:00
)
chunk chunking f t
applies chunked
selector f
on t
Chunked selectors
You may find (%>)
useful for chaining selectors together, e.g. drop 5 %> take 2
chunk_again chunking f
applies chunked
selector f
as a selector
Take every nth chunk, specifically 0
th, n
th, 2n
th, 3n
th, ...
Lightweight chunking
These are strictly less flexible than chunking functions provided in Chunking
, but can be significantly more efficient than the equivalent implemented with chunk ...
Infix operators
Composition, mainly for chunked selectors
f1 %> f2
is equivalent to fun x -> x |> f1 |> f2
.
Resolution
Resolves a Timere object into a concrete interval sequence
Pretty printers
val string_of_timestamp :
?display_using_tz:Time_zone.t ->
?format:string ->
timestamp ->
string
Pretty printing for timestamp.
Follows same format string rules and default format string as Date_time.to_string
.
val pp_timestamp :
?display_using_tz:Time_zone.t ->
?format:string ->
unit ->
Format.formatter ->
timestamp ->
unit
val string_of_interval :
?display_using_tz:Time_zone.t ->
?format:string ->
interval ->
string
Pretty printing for interval.
Default format string:
[{syear} {smon:Xxx} {smday:0X} {shour:0X}:{smin:0X}:{ssec:0X} \ {stzoff-sign}{stzoff-hour:0X}:{stzoff-min:0X}:{stzoff-sec:0X}, {eyear} \ {emon:Xxx} {emday:0X} {ehour:0X}:{emin:0X}:{esec:0X} \ {etzoff-sign}{etzoff-hour:0X}:{etzoff-min:0X}:{etzoff-sec:0X})
Follows same format string rules as Date_time.to_string
, but tags are prefixed with 's' for "start time", and 'e' for "end exc time", e.g. for interval (x, y)
{syear}
gives year of thex
{ehour:cX}
gives hour of they
val pp_interval :
?display_using_tz:Time_zone.t ->
?format:string ->
unit ->
Format.formatter ->
interval ->
unit
val pp_intervals :
?display_using_tz:Time_zone.t ->
?format:string ->
?sep:unit Fmt.t ->
unit ->
Format.formatter ->
interval Seq.t ->
unit
S-expressions
These functions are suitable for debugging, serializing and deserializing timeres.
The sexp is a precise description of the steps used to construct a timere. As such deserialization is accurate and goes through the exact same construction steps (including validation) as one would using the construction API directly.