Cldr.Calendar.Kday (Cldr Calendars v1.13.0) View Source
Provide K-Day functions for Dates, DateTimes and NaiveDateTimes.
Link to this section Summary
Functions
Return the date of the first day_of_week
on or after the
specified date
.
Return the date of the day_of_week
after the
specified date
.
Return the date of the day_of_week
before the
specified date
.
Return the date of the day_of_week
nearest the
specified date
.
Return the date of the day_of_week
on or after the
specified date
.
Return the date of the day_of_week
on or before the
specified date
.
Return the date of the last day_of_week
on or before the
specified date
.
Return the date of the nth
day_of_week
on or before/after the
specified date
.
Link to this section Functions
Specs
first_kday(Calendar.day() | Date.t(), Cldr.Calendar.day_of_week()) :: Calendar.day() | Date.t()
Return the date of the first day_of_week
on or after the
specified date
.
Arguments
date
is%Date{}
, a%DateTime{}
,%NaiveDateTime{}
or ISO daysk
is an integer day of the week.
Returns
- A
%Date{”}
in the calendar of the date provided as an argument
Examples
# US election day
iex> Cldr.Calendar.Kday.first_kday(~D[2017-11-02], 2)
~D[2017-11-07]
# US Daylight savings end
iex> Cldr.Calendar.Kday.first_kday(~D[2017-11-01], 7)
~D[2017-11-05]
Specs
kday_after(Calendar.day() | Date.t(), Cldr.Calendar.day_of_week()) :: Calendar.day() | Date.t()
Return the date of the day_of_week
after the
specified date
.
Arguments
date
is%Date{}
, a%DateTime{}
,%NaiveDateTime{}
or a Rata Diek
is an integer day of the week.
Returns
- A
%Date{}
in the calendar of the date provided as an argument
Examples
iex> Cldr.Calendar.Kday.kday_after(~D[2016-02-29], 2)
~D[2016-03-01]
iex> Cldr.Calendar.Kday.kday_after(~D[2017-11-30], 1)
~D[2017-12-04]
iex> Cldr.Calendar.Kday.kday_after(~D[2017-06-30], 6)
~D[2017-07-01]
Specs
kday_before(Calendar.day() | Date.t(), Cldr.Calendar.day_of_week()) :: Calendar.day() | Date.t()
Return the date of the day_of_week
before the
specified date
.
Arguments
date
is%Date{}
, a%DateTime{}
,%NaiveDateTime{}
or a Rata Diek
is an integer day of the week.
Returns
- A
%Date{}
in the calendar of the date provided as an argument
Examples
iex> Cldr.Calendar.Kday.kday_before(~D[2016-02-29], 2)
~D[2016-02-23]
iex> Cldr.Calendar.Kday.kday_before(~D[2017-11-30], 1)
~D[2017-11-27]
# 6 means Saturday. Use either the integer value or the atom form.
iex> Cldr.Calendar.Kday.kday_before(~D[2017-06-30], 6)
~D[2017-06-24]
Specs
kday_nearest(Calendar.day() | Date.t(), Cldr.Calendar.day_of_week()) :: Calendar.day() | Date.t()
Return the date of the day_of_week
nearest the
specified date
.
Arguments
date
is%Date{}
, a%DateTime{}
,%NaiveDateTime{}
or a Rata Diek
is an integer day of the week.
Returns
- A
%Date{}
in the calendar of the date provided as an argument
Examples
iex> Cldr.Calendar.Kday.kday_nearest(~D[2016-02-29], 2)
~D[2016-03-01]
iex> Cldr.Calendar.Kday.kday_nearest(~D[2017-11-30], 1)
~D[2017-11-27]
iex> Cldr.Calendar.Kday.kday_nearest(~D[2017-06-30], 6)
~D[2017-07-01]
Specs
kday_on_or_after(Calendar.day() | Date.t(), Cldr.Calendar.day_of_week()) :: Calendar.day() | Date.t()
Return the date of the day_of_week
on or after the
specified date
.
Arguments
date
is%Date{}
, a%DateTime{}
,%NaiveDateTime{}
or a Rata Diek
is an integer day of the week.
Returns
- A
%Date{}
in the calendar of the date provided as an argument
Examples
iex> Cldr.Calendar.Kday.kday_on_or_after(~D[2016-02-29], 2)
~D[2016-03-01]
iex> Cldr.Calendar.Kday.kday_on_or_after(~D[2017-11-30], 1)
~D[2017-12-04]
iex> Cldr.Calendar.Kday.kday_on_or_after(~D[2017-06-30], 6)
~D[2017-07-01]
Specs
kday_on_or_before(Calendar.day() | Date.t(), Cldr.Calendar.day_of_week()) :: Calendar.day() | Date.t()
Return the date of the day_of_week
on or before the
specified date
.
Arguments
date
is%Date{}
, a%DateTime{}
,%NaiveDateTime{}
or a Rata Diek
is an integer day of the week.
Returns
- A
%Date{}
in the calendar of the date provided as an argument
Examples
iex> Cldr.Calendar.Kday.kday_on_or_before(~D[2016-02-29], 2)
~D[2016-02-23]
iex> Cldr.Calendar.Kday.kday_on_or_before(~D[2017-11-30], 1)
~D[2017-11-27]
iex> Cldr.Calendar.Kday.kday_on_or_before(~D[2017-06-30], 6)
~D[2017-06-24]
Specs
last_kday(Calendar.day() | Date.t(), Cldr.Calendar.day_of_week()) :: Calendar.day() | Date.t()
Return the date of the last day_of_week
on or before the
specified date
.
Arguments
date
is%Date{}
, a%DateTime{}
,%NaiveDateTime{}
or a Rata Diek
is an integer day of the week.
Returns
- A
%Date{}
in the calendar of the date provided as an argument
Example
# Memorial Day in the US
iex> Cldr.Calendar.Kday.last_kday(~D[2017-05-31], 1)
~D[2017-05-29]
Specs
nth_kday(Calendar.day() | Date.t(), integer(), Cldr.Calendar.day_of_week()) :: Calendar.day() | Date.t()
Return the date of the nth
day_of_week
on or before/after the
specified date
.
Arguments
date
is%Date{}
, a%DateTime{}
,%NaiveDateTime{}
or a Rata Dien
is the cardinal number ofk
before (negativen
) or after (positiven
) the specified datek
is an integer day of the week.
Returns
- A
%Date{}
in the calendar of the date provided as an argument
Examples
# Thanksgiving in the US
iex> Cldr.Calendar.Kday.nth_kday(~D[2017-11-01], 4, 4)
~D[2017-11-23]
# Labor day in the US
iex> Cldr.Calendar.Kday.nth_kday(~D[2017-09-01], 1, 1)
~D[2017-09-04]
# Daylight savings time starts in the US
iex> Cldr.Calendar.Kday.nth_kday(~D[2017-03-01], 2, 7)
~D[2017-03-12]