GoodTimes.Generate

Generate streams of datetimes.

Generate a stream of datetimes, starting with the input datetime and stepping forward or backward by some time unit. All functions operate on an Erlang datetime, and returns a Stream of datetime elements.

There are functions stepping a second, minute, hour, week, day, month or year at a time. Step forward with all_<unit>_after/1, or backward with all_<unit>_before/1.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_days_after |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 28}, {18, 30, 45}},
 {{2015, 3, 1}, {18, 30, 45}}]
Source

Summary

all_days_after(datetime)

Returns a Stream of datetimes, starting with datetime, stepping forward one day at a time

all_days_before(datetime)

Returns a Stream of datetimes, starting with datetime, stepping backward one day at a time

all_hours_after(datetime)

Returns a Stream of datetimes, starting with datetime, stepping forward one hour at a time

all_hours_before(datetime)

Returns a Stream of datetimes, starting with datetime, stepping backward one hour at a time

all_minutes_after(datetime)

Returns a Stream of datetimes, starting with datetime, stepping forward one minute at a time

all_minutes_before(datetime)

Returns a Stream of datetimes, starting with datetime, stepping backward one minute at a time

all_months_after(datetime)

Returns a Stream of datetimes, starting with datetime, stepping forward one month at a time

all_months_before(datetime)

Returns a Stream of datetimes, starting with datetime, stepping backward one month at a time

all_seconds_after(datetime)

Returns a Stream of datetimes, starting with datetime, stepping forward one second at a time

all_seconds_before(datetime)

Returns a Stream of datetimes, starting with datetime, stepping backward one second at a time

all_weeks_after(datetime)

Returns a Stream of datetimes, starting with datetime, stepping forward one week at a time

all_weeks_before(datetime)

Returns a Stream of datetimes, starting with datetime, stepping backward one week at a time

all_years_after(datetime)

Returns a Stream of datetimes, starting with datetime, stepping forward one year at a time

all_years_before(datetime)

Returns a Stream of datetimes, starting with datetime, stepping backward one year at a time

Functions

all_days_after(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping forward one day at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_days_after |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 28}, {18, 30, 45}},
 {{2015, 3, 1}, {18, 30, 45}}]
Source
all_days_before(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping backward one day at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_days_before |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 26}, {18, 30, 45}},
 {{2015, 2, 25}, {18, 30, 45}}]
Source
all_hours_after(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping forward one hour at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_hours_after |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 27}, {19, 30, 45}},
 {{2015, 2, 27}, {20, 30, 45}}]
Source
all_hours_before(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping backward one hour at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_hours_before |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 27}, {17, 30, 45}},
 {{2015, 2, 27}, {16, 30, 45}}]
Source
all_minutes_after(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping forward one minute at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_minutes_after |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 27}, {18, 31, 45}},
 {{2015, 2, 27}, {18, 32, 45}}]
Source
all_minutes_before(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping backward one minute at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_minutes_before |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 27}, {18, 29, 45}},
 {{2015, 2, 27}, {18, 28, 45}}]
Source
all_months_after(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping forward one month at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_months_after |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 3, 27}, {18, 30, 45}},
 {{2015, 4, 27}, {18, 30, 45}}]
Source
all_months_before(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping backward one month at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_months_before |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 1, 27}, {18, 30, 45}},
 {{2014, 12, 27}, {18, 30, 45}}]
Source
all_seconds_after(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping forward one second at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_seconds_after |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 27}, {18, 30, 46}},
 {{2015, 2, 27}, {18, 30, 47}}]
Source
all_seconds_before(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping backward one second at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_seconds_before |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 27}, {18, 30, 44}},
 {{2015, 2, 27}, {18, 30, 43}}]
Source
all_weeks_after(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping forward one week at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_weeks_after |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 3, 6}, {18, 30, 45}},
 {{2015, 3, 13}, {18, 30, 45}}]
Source
all_weeks_before(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping backward one week at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_weeks_before |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2015, 2, 20}, {18, 30, 45}},
 {{2015, 2, 13}, {18, 30, 45}}]
Source
all_years_after(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping forward one year at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_years_after |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2016, 2, 27}, {18, 30, 45}},
 {{2017, 2, 27}, {18, 30, 45}}]
Source
all_years_before(datetime)

Specs:

Returns a Stream of datetimes, starting with datetime, stepping backward one year at a time.

Examples

iex> {{2015, 2, 27}, {18, 30, 45}} |> all_years_before |> Enum.take 3
[{{2015, 2, 27}, {18, 30, 45}}, {{2014, 2, 27}, {18, 30, 45}},
 {{2013, 2, 27}, {18, 30, 45}}]
Source