View Source ExCycle.State (ex_cycle v0.7.2)
The ExCycle.State
represents the state of the next generated datetime.
Summary
Functions
Initializes the state.
Creates a new state.
The next
dates will be the same as origin
.
Resets the state.
update_next/3
is an helper to update the next value.
Types
@type datetime() :: Date.t() | DateTime.t() | NaiveDateTime.t()
@type t() :: %ExCycle.State{ exhausted?: boolean(), iteration: non_neg_integer(), next: NaiveDateTime.t(), origin: NaiveDateTime.t(), result: DateTime.t() | NaiveDateTime.t() | ExCycle.Span.t() | nil, week_starting_on: :default | atom() }
Functions
Initializes the state.
This function is important when we need the state to jump to the future, compared to the origin date.
This occurred when we used
occurences
with a date different of the current datetime or the origin datetime specified (akastarts_at
in rule).
Examples
iex> ExCycle.State.init(%ExCycle.State{next: ~N[2024-01-01 10:00:00]}, ~D[2024-01-02])
%ExCycle.State{next: ~N[2024-01-02 00:00:00]}
iex> ExCycle.State.init(%ExCycle.State{next: ~N[2024-01-01 10:00:00]}, ~D[2024-01-01])
%ExCycle.State{next: ~N[2024-01-01 10:00:00]}
iex> ExCycle.State.init(%ExCycle.State{next: ~N[2024-01-01 10:00:00]}, ~N[2024-01-01 10:01:01])
%ExCycle.State{next: ~N[2024-01-02 10:01:01]}
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]}
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]}
@spec set_next(t(), NaiveDateTime.t()) :: t()
update_next/3
is an helper to update the next value.