ExCycle.State (ex_cycle v0.3.0)
The ExCycle.State
represents the state of the next generated datetime.
Summary
Functions
Creates a new state.
The next
dates will be the same as origin
.
Creates a new state specifying the origin
and the next
(aka from
is this context).
Resets the state.
update_next/3
is an helper to update the next value.
Types
Link to this type
datetime()
@type datetime() :: Date.t() | DateTime.t() | NaiveDateTime.t()
@type t() :: %ExCycle.State{ next: NaiveDateTime.t(), origin: NaiveDateTime.t(), result: DateTime.t() | NaiveDateTime.t() | ExCycle.Span.t() | nil }
Functions
Link to this function
apply_duration(state, duration)
Link to this function
apply_timezone(state, timezone)
Link to this function
new(origin \\ NaiveDateTime.utc_now())
Creates a new state.
The next
dates will be the same as origin
.
Examples
iex> new(~D[2024-01-01])
%ExCycle.State{origin: ~N[2024-01-01 00:00:00], next: ~N[2024-01-01 00:00:00]}
iex> new(~N[2024-01-01 10:00:00])
%ExCycle.State{origin: ~N[2024-01-01 10:00:00], next: ~N[2024-01-01 10:00:00]}
Link to this function
new(origin, from)
Creates a new state specifying the origin
and the next
(aka from
is this context).
Examples
iex> new(~D[2024-01-01], ~D[2024-02-02])
%ExCycle.State{origin: ~N[2024-01-01 00:00:00], next: ~N[2024-02-02 00:00:00]}
iex> new(~N[2024-01-01 10:00:00], ~D[2024-02-02])
%ExCycle.State{origin: ~N[2024-01-01 10:00:00], next: ~N[2024-02-02 00:00:00]}
iex> new(~N[2024-01-01 10:00:00], ~N[2024-02-02 10:00:00])
%ExCycle.State{origin: ~N[2024-01-01 10:00:00], next: ~N[2024-02-02 10:00:00]}
Link to this function
reset(state)
Resets the state.
By resetting, we means set the origin
value equal to next
value.
Examples
iex> reset(%ExCycle.State{origin: ~N[2024-03-01 00:00:00], next: ~N[2024-06-01 00:00:00]})
%ExCycle.State{origin: ~N[2024-06-01 00:00:00], next: ~N[2024-06-01 00:00:00]}
Link to this function
set_next(state, datetime)
Link to this function
set_result(state)
Link to this function
update_next(datetime_state, fun)
update_next/3
is an helper to update the next value.