GoodTimes
Convenient and expressive functions dealing with dates and times.
This is the core module of the GoodTimes
library. For other modules and
their functionality, see Associated modules below.
Unless explicitly stated, all functions operate on and return an Erlang datetime based on the Coordinated Universal Time (UTC).
Functions overview
The following functions are available for each time unit (second, minute, hour, day, week, month, or year); all return a datetime that is offset the specified amount of time units.
<time_units>_after/2
<time_units>_before/2
<time_units>_from_now/1
<time_units>_ago/1
You can use the following functions when only adjusting the datetime by a single time unit.
a_<time_unit>_after/1
a_<time_unit>_before/1
a_<time_unit>_from_now/0
a_<time_unit>_ago/0
In addition, now/0
and at/2
are included for convenience.
Examples
iex> now
{{2015, 2, 27}, {18, 30, 45}}
iex> an_hour_ago
{{2015, 2, 27}, {17, 30, 45}}
iex> a_month_before {{2016, 3, 31}, {9, 30, 0}}
{{2016, 2, 29}, {9, 30, 0}}
iex> 2 |> weeks_from_now |> at {12, 15, 0}
{{2015, 3, 13}, {12, 15, 0}}
Known limitations
As the entire library builds upon Erlang’s calendar module, dates before year 0 are not supported.
Associated modules
Aside from the core module, the GoodTimes
library consistes of these
modules.
GoodTimes.Boundary
- find bounderies between time units.GoodTimes.Convert
- convert dates, datetimes and times.GoodTimes.Date
- functions operating on and returning dates.GoodTimes.Generate
- functions generating streams of time units.
Summary↑
a_day_after(datetime) | Returns the UTC date and time a day after the given datetime |
a_day_ago() | Returns the UTC date and time a day ago |
a_day_before(datetime) | Returns the UTC date and time a day before the given datetime |
a_day_from_now() | Returns the UTC date and time a day from now |
a_minute_after(datetime) | Returns the UTC date and time a minute after the given datetime |
a_minute_ago() | Returns the UTC date and time a minute ago |
a_minute_before(datetime) | Returns the UTC date and time a minute before the given datetime |
a_minute_from_now() | Returns the UTC date and time a minute from now |
a_month_after(datetime) | Returns the UTC date and time a month after the given datetime |
a_month_ago() | Returns the UTC date and time a month ago |
a_month_before(datetime) | Returns the UTC date and time a month before the given datetime |
a_month_from_now() | Returns the UTC date and time a month from now |
a_second_after(datetime) | Returns the UTC date and time a second after the given datetime |
a_second_ago() | Returns the UTC date and time a second ago |
a_second_before(datetime) | Returns the UTC date and time a second before the given datetime |
a_second_from_now() | Returns the UTC date and time a second from now |
a_week_after(datetime) | Returns the UTC date and time a week after the given datetime |
a_week_ago() | Returns the UTC date and time a week ago |
a_week_before(datetime) | Returns the UTC date and time a week before the given datetime |
a_week_from_now() | Returns the UTC date and time a week from now |
a_year_after(datetime) | Returns the UTC date and time a year after the given datetime |
a_year_ago() | Returns the UTC date and time a year ago |
a_year_before(datetime) | Returns the UTC date and time a year before the given datetime |
a_year_from_now() | Returns the UTC date and time a year from now |
an_hour_after(datetime) | Returns the UTC date and time an hour after the given datetime |
an_hour_ago() | Returns the UTC date and time an hour ago |
an_hour_before(datetime) | Returns the UTC date and time an hour before the given datetime |
an_hour_from_now() | Returns the UTC date and time an hour from now |
at(date_or_datetime, time) | Merges the date from the given date or datetime with the given time |
days_after(days, datetime) | Returns the UTC date and time the specified days after the given datetime |
days_ago(days) | Returns the UTC date and time the specified days ago |
days_before(days, datetime) | Returns the UTC date and time the specified days before the given datetime |
days_from_now(days) | Returns the UTC date and time the specified days from now |
hours_after(hours, datetime) | Returns the UTC date and time the specified hours after the given datetime |
hours_ago(hours) | Returns the UTC date and time the specified hours ago |
hours_before(hours, datetime) | Returns the UTC date and time the specified hours before the given datetime |
hours_from_now(hours) | Returns the UTC date and time the specified hours from now |
minutes_after(minutes, datetime) | Returns the UTC date and time the specified minutes after the given datetime |
minutes_ago(minutes) | Returns the UTC date and time the specified minutes ago |
minutes_before(minutes, datetime) | Returns the UTC date and time the specified minutes before the given datetime |
minutes_from_now(minutes) | Returns the UTC date and time the specified minutes from now |
months_after(months, arg2) | Returns the UTC date and time the specified months after the given datetime |
months_ago(months) | Returns the UTC date and time the specified months ago |
months_before(months, datetime) | Returns the UTC date and time the specified months before the given datetime |
months_from_now(months) | Returns the UTC date and time the specified months from now |
now() | Returns the current UTC time as a datetime |
seconds_after(seconds, datetime) | Returns the UTC date and time the specified seconds after the given datetime |
seconds_ago(seconds) | Returns the UTC date and time the specified seconds ago |
seconds_before(seconds, datetime) | Returns the UTC date and time the specified seconds before the given datetime |
seconds_from_now(seconds) | Returns the UTC date and time the specified seconds from now |
weeks_after(weeks, datetime) | Returns the UTC date and time the specified weeks after the given datetime |
weeks_ago(weeks) | Returns the UTC date and time the specified weeks ago |
weeks_before(weeks, datetime) | Returns the UTC date and time the specified weeks before the given datetime |
weeks_from_now(weeks) | Returns the UTC date and time the specified weeks from now |
years_after(years, datetime) | Returns the UTC date and time the specified years after the given datetime |
years_ago(years) | Returns the UTC date and time the specified years ago |
years_before(years, datetime) | Returns the UTC date and time the specified years before the given datetime |
years_from_now(years) | Returns the UTC date and time the specified years from now |
Types ↑
year :: non_neg_integer
month :: 1 .. 12
day :: 1 .. 31
hour :: 0 .. 23
minute :: 0 .. 59
second :: 0 .. 59
Functions
Specs:
Returns the UTC date and time a day after the given datetime.
Examples
iex> a_day_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 28}, {18, 30, 45}}
Specs:
- a_day_ago :: datetime
Returns the UTC date and time a day ago.
Examples
iex> a_day_ago
{{2015, 2, 26}, {18, 30, 45}}
Specs:
Returns the UTC date and time a day before the given datetime.
Examples
iex> a_day_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 26}, {18, 30, 45}}
Specs:
- a_day_from_now :: datetime
Returns the UTC date and time a day from now.
Examples
iex> a_day_from_now
{{2015, 2, 28}, {18, 30, 45}}
Specs:
Returns the UTC date and time a minute after the given datetime.
Examples
iex> a_minute_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {18, 31, 45}}
Specs:
- a_minute_ago :: datetime
Returns the UTC date and time a minute ago.
Examples
iex> a_minute_ago
{{2015, 2, 27}, {18, 29, 45}}
Specs:
Returns the UTC date and time a minute before the given datetime.
Examples
iex> a_minute_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {18, 29, 45}}
Specs:
- a_minute_from_now :: datetime
Returns the UTC date and time a minute from now.
Examples
iex> a_minute_from_now
{{2015, 2, 27}, {18, 31, 45}}
Specs:
Returns the UTC date and time a month after the given datetime.
Examples
iex> a_month_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 3, 27}, {18, 30, 45}}
Specs:
- a_month_ago :: datetime
Returns the UTC date and time a month ago.
Examples
iex> a_month_ago
{{2015, 1, 27}, {18, 30, 45}}
Specs:
Returns the UTC date and time a month before the given datetime.
Examples
iex> a_month_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 1, 27}, {18, 30, 45}}
Specs:
- a_month_from_now :: datetime
Returns the UTC date and time a month from now.
Examples
iex> a_month_from_now
{{2015, 3, 27}, {18, 30, 45}}
Specs:
Returns the UTC date and time a second after the given datetime.
Examples
iex> a_second_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {18, 30, 46}}
Specs:
- a_second_ago :: datetime
Returns the UTC date and time a second ago.
iex> a_second_ago
{{2015, 2, 27}, {18, 30, 44}}
Specs:
Returns the UTC date and time a second before the given datetime.
Examples
iex> a_second_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {18, 30, 44}}
Specs:
- a_second_from_now :: datetime
Returns the UTC date and time a second from now.
Examples
iex> a_second_from_now
{{2015, 2, 27}, {18, 30, 46}}
Specs:
Returns the UTC date and time a week after the given datetime.
Examples
iex> a_week_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 3, 6}, {18, 30, 45}}
Specs:
- a_week_ago :: datetime
Returns the UTC date and time a week ago.
Examples
iex> a_week_ago
{{2015, 2, 20}, {18, 30, 45}}
Specs:
Returns the UTC date and time a week before the given datetime.
Examples
iex> a_week_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 20}, {18, 30, 45}}
Specs:
- a_week_from_now :: datetime
Returns the UTC date and time a week from now.
Examples
iex> a_week_from_now
{{2015, 3, 6}, {18, 30, 45}}
Specs:
Returns the UTC date and time a year after the given datetime.
Examples
iex> a_year_after {{2015, 2, 27}, {18, 30, 45}}
{{2016, 2, 27}, {18, 30, 45}}
Specs:
- a_year_ago :: datetime
Returns the UTC date and time a year ago.
Examples
iex> a_year_ago
{{2014, 2, 27}, {18, 30, 45}}
Specs:
Returns the UTC date and time a year before the given datetime.
Examples
iex> a_year_before {{2015, 2, 27}, {18, 30, 45}}
{{2014, 2, 27}, {18, 30, 45}}
Specs:
- a_year_from_now :: datetime
Returns the UTC date and time a year from now.
Examples
iex> a_year_from_now
{{2016, 2, 27}, {18, 30, 45}}
Specs:
Returns the UTC date and time an hour after the given datetime.
Examples
iex> an_hour_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {19, 30, 45}}
Specs:
- an_hour_ago :: datetime
Returns the UTC date and time an hour ago.
Examples
iex> an_hour_ago
{{2015, 2, 27}, {17, 30, 45}}
Specs:
Returns the UTC date and time an hour before the given datetime.
Examples
iex> an_hour_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {17, 30, 45}}
Specs:
- an_hour_from_now :: datetime
Returns the UTC date and time an hour from now.
Examples
iex> an_hour_from_now
{{2015, 2, 27}, {19, 30, 45}}
Specs:
Merges the date from the given date or datetime with the given time.
Examples
iex> now |> at {10, 30, 15}
{{2015, 2, 27}, {10, 30, 15}}
iex> {2015, 2, 27} |> at {10, 30, 15}
{{2015, 2, 27}, {10, 30, 15}}
Specs:
Returns the UTC date and time the specified days after the given datetime.
Examples
iex> 3 |> days_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 3, 2}, {18, 30, 45}}
Specs:
- days_ago(integer) :: datetime
Returns the UTC date and time the specified days ago.
Examples
iex> 7 |> days_ago
{{2015, 2, 20}, {18, 30, 45}}
Specs:
Returns the UTC date and time the specified days before the given datetime.
Examples
iex> 3 |> days_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 24}, {18, 30, 45}}
Specs:
- days_from_now(integer) :: datetime
Returns the UTC date and time the specified days from now.
Examples
iex> 2 |> days_from_now
{{2015, 3, 1}, {18, 30, 45}}
Specs:
Returns the UTC date and time the specified hours after the given datetime.
Examples
iex> 15 |> hours_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 28}, {9, 30, 45}}
Specs:
- hours_ago(integer) :: datetime
Returns the UTC date and time the specified hours ago.
Examples
iex> 2 |> hours_ago
{{2015, 2, 27}, {16, 30, 45}}
Specs:
Returns the UTC date and time the specified hours before the given datetime.
Examples
iex> 15 |> hours_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {3, 30, 45}}
Specs:
- hours_from_now(integer) :: datetime
Returns the UTC date and time the specified hours from now.
Examples
iex> 6 |> hours_from_now
{{2015, 2, 28}, {0, 30, 45}}
Specs:
Returns the UTC date and time the specified minutes after the given datetime.
Examples
iex> 15 |> minutes_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {18, 45, 45}}
Specs:
- minutes_ago(integer) :: datetime
Returns the UTC date and time the specified minutes ago.
Examples
iex> 5 |> minutes_ago
{{2015, 2, 27}, {18, 25, 45}}
Specs:
Returns the UTC date and time the specified minutes before the given datetime.
Examples
iex> 15 |> minutes_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {18, 15, 45}}
Specs:
- minutes_from_now(integer) :: datetime
Returns the UTC date and time the specified minutes from now.
Examples
iex> 10 |> minutes_from_now
{{2015, 2, 27}, {18, 40, 45}}
Specs:
Returns the UTC date and time the specified months after the given datetime.
Examples
iex> 3 |> months_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 5, 27}, {18, 30, 45}}
Specs:
- months_ago(integer) :: datetime
Returns the UTC date and time the specified months ago.
Examples
iex> 2 |> months_ago
{{2014, 12, 27}, {18, 30, 45}}
Specs:
Returns the UTC date and time the specified months before the given datetime.
Examples
iex> 3 |> months_before {{2015, 2, 27}, {18, 30, 45}}
{{2014, 11, 27}, {18, 30, 45}}
Specs:
- months_from_now(integer) :: datetime
Returns the UTC date and time the specified months from now.
Examples
iex> 2 |> months_from_now
{{2015, 4, 27}, {18, 30, 45}}
Specs:
- now :: datetime
Returns the current UTC time as a datetime.
Examples
iex> now
{{2015, 2, 27}, {18, 30, 45}}
Specs:
Returns the UTC date and time the specified seconds after the given datetime.
Examples
iex> 15 |> seconds_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {18, 31, 0}}
Specs:
- seconds_ago(integer) :: datetime
Returns the UTC date and time the specified seconds ago.
Examples
iex> 20 |> seconds_ago
{{2015, 2, 27}, {18, 30, 25}}
Specs:
Returns the UTC date and time the specified seconds before the given datetime.
Examples
iex> 15 |> seconds_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 27}, {18, 30, 30}}
Specs:
- seconds_from_now(integer) :: datetime
Returns the UTC date and time the specified seconds from now.
Examples
iex> 15 |> seconds_from_now
{{2015, 2, 27}, {18, 31, 0}}
Specs:
Returns the UTC date and time the specified weeks after the given datetime.
Examples
iex> 3 |> weeks_after {{2015, 2, 27}, {18, 30, 45}}
{{2015, 3, 20}, {18, 30, 45}}
Specs:
- weeks_ago(integer) :: datetime
Returns the UTC date and time the specified weeks ago.
Examples
iex> 2 |> weeks_ago
{{2015, 2, 13}, {18, 30, 45}}
Specs:
Returns the UTC date and time the specified weeks before the given datetime.
Examples
iex> 3 |> weeks_before {{2015, 2, 27}, {18, 30, 45}}
{{2015, 2, 6}, {18, 30, 45}}
Specs:
- weeks_from_now(integer) :: datetime
Returns the UTC date and time the specified weeks from now.
Examples
iex> 2 |> weeks_from_now
{{2015, 3, 13}, {18, 30, 45}}
Specs:
Returns the UTC date and time the specified years after the given datetime.
Examples
iex> 3 |> years_after {{2015, 2, 27}, {18, 30, 45}}
{{2018, 2, 27}, {18, 30, 45}}
Specs:
- years_ago(integer) :: datetime
Returns the UTC date and time the specified years ago.
Examples
iex> 2 |> years_ago
{{2013, 2, 27}, {18, 30, 45}}
Specs:
Returns the UTC date and time the specified years before the given datetime.
Examples
iex> 3 |> years_before {{2015, 2, 27}, {18, 30, 45}}
{{2012, 2, 27}, {18, 30, 45}}
Specs:
- years_from_now(integer) :: datetime
Returns the UTC date and time the specified years from now.
Examples
iex> 2 |> years_from_now
{{2017, 2, 27}, {18, 30, 45}}