timex v3.6.2 Timex.Protocol protocol View Source

This protocol defines the API for functions which take a Date, NaiveDateTime, or DateTime as input.

Link to this section Summary

Functions

Get a new version of the date/time value representing the beginning of the day

Get a new version of the date/time value representing the beginning of it's month

Get a new version of the date/time value representing the beginning of it's quarter

Get a new version of the date/time value representing the beginning of it's week, providing a weekday name (as an atom) for the day which starts the week, i.e. :mon.

Get a new version of the date/time value representing the beginning of it's year

Get the century a date/time value is in

Get the ordinal day number of the given date/time value

Get the number of days in the month for the given date/time value

Get a new version of the date/time value representing the end of the day

Get a new version of the date/time value representing the ending of it's month

Get a new version of the date/time value representing the ending of it's quarter

Get a new version of the date/time value representing the ending of it's week, providing a weekday name (as an atom) for the day which starts the week, i.e. :mon.

Get a new version of the date/time value representing the ending of it's year

Shifts the given date/time value to the ISO day given

Return a boolean indicating whether the date/time value is in a leap year

Determine if the provided date/time value is valid.

Return a pair {year, week number} (as defined by ISO 8601) that the given date/time value falls on.

Get the quarter for the given date/time value

Set fields on a date/time value using a list of unit/value pairs

Shift a date/time value using a list of shift unit/value pairs

Convert a date/time value to a Date

Convert a date/time value to a DateTime. An optional timezone can be provided, UTC will be assumed if one is not provided.

Convert a date/time value to it's Erlang tuple variant i.e. Date becomes {y,m,d}, DateTime/NaiveDateTime become {{y,m,d},{h,mm,s}}

Convert a date/time value to gregorian microseconds (microseconds since the start of year zero)

Convert a date/time value to gregorian seconds (seconds since start of year zero)

Convert a date/time value to a Julian calendar date number

Convert a date/time value to a NaiveDateTime

Convert a date/time value to seconds since the UNIX Epoch

Get the week number of the given date/time value, starting at 1

Get the ordinal weekday number of the given date/time value

Link to this section Types

Link to this section Functions

Link to this function

beginning_of_day(datetime)

View Source
beginning_of_day(Timex.Types.valid_datetime()) ::
  Timex.Types.valid_datetime() | {:error, term()}

Get a new version of the date/time value representing the beginning of the day

Link to this function

beginning_of_month(datetime)

View Source
beginning_of_month(Timex.Types.valid_datetime()) ::
  Timex.Types.valid_datetime() | {:error, term()}

Get a new version of the date/time value representing the beginning of it's month

Link to this function

beginning_of_quarter(datetime)

View Source
beginning_of_quarter(Timex.Types.valid_datetime()) ::
  Timex.Types.valid_datetime() | {:error, term()}

Get a new version of the date/time value representing the beginning of it's quarter

Link to this function

beginning_of_week(datetime, weekstart)

View Source

Get a new version of the date/time value representing the beginning of it's week, providing a weekday name (as an atom) for the day which starts the week, i.e. :mon.

Link to this function

beginning_of_year(datetime)

View Source
beginning_of_year(Timex.Types.year() | Timex.Types.valid_datetime()) ::
  Timex.Types.valid_datetime() | {:error, term()}

Get a new version of the date/time value representing the beginning of it's year

Get the century a date/time value is in

Get the ordinal day number of the given date/time value

Link to this function

days_in_month(datetime)

View Source
days_in_month(Timex.Types.valid_datetime()) ::
  Timex.Types.num_of_days() | {:error, term()}

Get the number of days in the month for the given date/time value

Get a new version of the date/time value representing the end of the day

Get a new version of the date/time value representing the ending of it's month

Link to this function

end_of_quarter(datetime)

View Source
end_of_quarter(Timex.Types.valid_datetime()) ::
  Timex.Types.valid_datetime() | {:error, term()}

Get a new version of the date/time value representing the ending of it's quarter

Get a new version of the date/time value representing the ending of it's week, providing a weekday name (as an atom) for the day which starts the week, i.e. :mon.

Get a new version of the date/time value representing the ending of it's year

Shifts the given date/time value to the ISO day given

Return a boolean indicating whether the date/time value is in a leap year

Link to this function

is_valid?(datetime)

View Source
is_valid?(Timex.Types.valid_datetime()) :: boolean() | {:error, term()}

Determine if the provided date/time value is valid.

Return a pair {year, week number} (as defined by ISO 8601) that the given date/time value falls on.

Link to this function

quarter(datetime)

View Source
quarter(Timex.Types.month() | Timex.Types.valid_datetime()) ::
  1..4 | {:error, term()}

Get the quarter for the given date/time value

Set fields on a date/time value using a list of unit/value pairs

Shift a date/time value using a list of shift unit/value pairs

Link to this function

to_date(datetime)

View Source
to_date(Timex.Types.valid_datetime()) :: Date.t() | {:error, term()}

Convert a date/time value to a Date

Link to this function

to_datetime(datetime, timezone \\ :utc)

View Source

Convert a date/time value to a DateTime. An optional timezone can be provided, UTC will be assumed if one is not provided.

Convert a date/time value to it's Erlang tuple variant i.e. Date becomes {y,m,d}, DateTime/NaiveDateTime become {{y,m,d},{h,mm,s}}

Link to this function

to_gregorian_microseconds(datetime)

View Source
to_gregorian_microseconds(Timex.Types.valid_datetime()) ::
  non_neg_integer() | {:error, term()}

Convert a date/time value to gregorian microseconds (microseconds since the start of year zero)

Link to this function

to_gregorian_seconds(datetime)

View Source
to_gregorian_seconds(Timex.Types.valid_datetime()) ::
  non_neg_integer() | {:error, term()}

Convert a date/time value to gregorian seconds (seconds since start of year zero)

Link to this function

to_julian(datetime)

View Source
to_julian(Timex.Types.valid_datetime()) :: float() | {:error, term()}

Convert a date/time value to a Julian calendar date number

Link to this function

to_naive_datetime(datetime)

View Source
to_naive_datetime(Timex.Types.valid_datetime()) ::
  NaiveDateTime.t() | {:error, term()}

Convert a date/time value to a NaiveDateTime

Convert a date/time value to seconds since the UNIX Epoch

Link to this function

week_of_month(datetime)

View Source
week_of_month(Timex.Types.valid_datetime()) ::
  Timex.Types.week_of_month() | {:error, term()}

Get the week number of the given date/time value, starting at 1

Get the ordinal weekday number of the given date/time value