time_traveller v0.1.0 TimeTraveller
Easily calculate the UTC representation of common local times. A light wrapper around Timex, TimeTraveller allows you to think in local time and get the UTC representation.
Link to this section Summary
Functions
Returns the UTC representation of the beginning of the day for the given date and timezone. The date can be a string in the format “YYYY-MM-DD” or a Date, DateTime, or NaiveDateTime struct. The date is interpreted as being in the timezone specified and the UTC datetime is returned
Returns the UTC representation of the beginning of the month for the given date and timezone. The date can be a string in the format “YYYY-MM-DD” or a Date, DateTime, or NaiveDateTime struct. The date is interpreted as being in the timezone specified and the UTC datetime is returned
Returns the UTC representation of the beginning of the week for the given date and timezone. The date can be a string in the format “YYYY-MM-DD” or a Date, DateTime, or NaiveDateTime struct. The date is interpreted as being in the timezone specified and the UTC datetime is returned. Week starts on Sunday
Returns the UTC representation of the beginning of the week for the given date and timezone. The date is interpreted as being in the timezone specified and the UTC datetime is returned
Returns the UTC representation of the beginning of the year for the given date and timezone. The date can be a string in the format “YYYY-MM-DD” or a Date, DateTime, or NaiveDateTime struct. The date is interpreted as being in the timezone specified and the UTC datetime is returned
Converts a NaiveDateTime to the specified timezone and then converts that to UTC
Link to this section Functions
beginning_of_day_utc( String.t() | Date.t() | NaiveDateTime.t() | DateTime.t(), Timex.Types.valid_timezone() ) :: DateTime.t()
Returns the UTC representation of the beginning of the day for the given date and timezone. The date can be a string in the format “YYYY-MM-DD” or a Date, DateTime, or NaiveDateTime struct. The date is interpreted as being in the timezone specified and the UTC datetime is returned.
Examples
iex> TimeTraveller.beginning_of_day_utc("2018-09-01", "America/Denver")
#DateTime<2018-09-01 06:00:00Z>
beginning_of_month_utc( String.t() | Date.t() | NaiveDateTime.t() | DateTime.t(), Timex.Types.valid_timezone() ) :: DateTime.t()
Returns the UTC representation of the beginning of the month for the given date and timezone. The date can be a string in the format “YYYY-MM-DD” or a Date, DateTime, or NaiveDateTime struct. The date is interpreted as being in the timezone specified and the UTC datetime is returned.
Examples
iex> TimeTraveller.beginning_of_month_utc("2018-09-03", "America/Denver")
#DateTime<2018-09-01 06:00:00Z>
beginning_of_week_utc( String.t() | Date.t() | NaiveDateTime.t() | DateTime.t(), Timex.Types.valid_timezone() ) :: DateTime.t()
Returns the UTC representation of the beginning of the week for the given date and timezone. The date can be a string in the format “YYYY-MM-DD” or a Date, DateTime, or NaiveDateTime struct. The date is interpreted as being in the timezone specified and the UTC datetime is returned. Week starts on Sunday.
Examples
iex> TimeTraveller.beginning_of_week_utc("2018-09-01", "America/Denver")
#DateTime<2018-08-26 06:00:00Z>
beginning_of_week_utc( String.t() | Date.t() | NaiveDateTime.t() | DateTime.t(), Timex.Types.valid_timezone(), Timex.Types.weekstart() ) :: DateTime.t()
Returns the UTC representation of the beginning of the week for the given date and timezone. The date is interpreted as being in the timezone specified and the UTC datetime is returned.
The weekstart can between 1..7, an atom e.g. :mon, or a string e.g. “Monday”
Examples
iex> TimeTraveller.beginning_of_week_utc("2018-09-01", "America/Denver")
#DateTime<2018-08-26 06:00:00Z>
beginning_of_year_utc( String.t() | Date.t() | NaiveDateTime.t() | DateTime.t(), Timex.Types.valid_timezone() ) :: DateTime.t()
Returns the UTC representation of the beginning of the year for the given date and timezone. The date can be a string in the format “YYYY-MM-DD” or a Date, DateTime, or NaiveDateTime struct. The date is interpreted as being in the timezone specified and the UTC datetime is returned.
Examples
iex> TimeTraveller.beginning_of_year_utc("2018-09-03", "America/Denver")
#DateTime<2018-01-01 07:00:00Z>
naive_utc(NaiveDateTime.t(), Timex.Types.valid_timezone()) :: DateTime.t()
Converts a NaiveDateTime to the specified timezone and then converts that to UTC.
Examples
iex> ndt = "2018-09-03" |> Timex.parse!("{YYYY}-{0M}-{0D}")
iex> TimeTraveller.naive_utc(ndt, "America/Denver")
#DateTime<2018-09-03 06:00:00Z>