timex v3.5.0 Timex.Timezone View Source
This module is used for looking up the timezone information for
a given point in time, in the desired zone. Timezones are dependent
not only on locale, but the date and time for which you are querying.
For instance, the timezone offset from UTC for Europe/Moscow
is different
for March 3rd of 2015, than it was in 2013. These differences are important,
and as such, all functions in this module are date/time sensitive, and where
omitted, the current date/time are assumed.
In addition to lookups, this module also does conversion of datetimes from one timezone period to another, and determining the difference between a date in one timezone period and the same date/time in another timezone period.
Link to this section Summary
Functions
Shifts the provided DateTime to the beginning of the day in it's timezone
Convert a date to the given timezone (either TimezoneInfo or a timezone name)
Determine what offset is required to convert a date into a target timezone
Shifts the provided DateTime to the end of the day in it's timezone
Determines if a given zone name exists
Gets timezone info for a given zone name and date. The date provided can either be an Erlang datetime tuple, or a DateTime struct, and if one is not provided, then the current date and time is returned
Gets the local timezone configuration for the current date and time
Gets the local timezone configuration for the provided date and time. The provided date and time can either be an Erlang datetime tuple, or a DateTime struct
This function takes one of the varying timezone representations
Given a timezone name as a string, and a date/time in the form of the number of seconds since year zero, attempt to resolve a TimezoneInfo for that date/time. If the time is ambiguous, AmbiguousTimezoneInfo will be returned. If no result is found, an error will be returned
Link to this section Functions
beginning_of_day(dt)
View Source
beginning_of_day(DateTime.t()) :: DateTime.t()
beginning_of_day(DateTime.t()) :: DateTime.t()
Shifts the provided DateTime to the beginning of the day in it's timezone
convert(date, tz)
View Source
convert(date :: DateTime.t(), tz :: Timex.AmbiguousTimezoneInfo.t()) ::
Timex.AmbiguousDateTime.t() | {:error, term()}
convert(date :: DateTime.t(), tz :: Timex.TimezoneInfo.t() | String.t()) ::
DateTime.t() | Timex.AmbiguousDateTime.t() | {:error, term()}
convert(date :: DateTime.t(), tz :: Timex.AmbiguousTimezoneInfo.t()) :: Timex.AmbiguousDateTime.t() | {:error, term()}
convert(date :: DateTime.t(), tz :: Timex.TimezoneInfo.t() | String.t()) :: DateTime.t() | Timex.AmbiguousDateTime.t() | {:error, term()}
Convert a date to the given timezone (either TimezoneInfo or a timezone name)
diff(dt, dest)
View Source
diff(date :: DateTime.t(), tz :: Timex.TimezoneInfo.t()) ::
integer() | {:error, term()}
diff(date :: DateTime.t(), tz :: Timex.TimezoneInfo.t()) :: integer() | {:error, term()}
Determine what offset is required to convert a date into a target timezone
end_of_day(dt)
View Source
end_of_day(DateTime.t()) :: DateTime.t()
end_of_day(DateTime.t()) :: DateTime.t()
Shifts the provided DateTime to the end of the day in it's timezone
exists?(zone) View Source
Determines if a given zone name exists
get(tz, datetime \\ :calendar.universal_time())
View Source
get(Timex.Types.valid_timezone(), Timex.Types.valid_datetime()) ::
Timex.TimezoneInfo.t() | Timex.AmbiguousTimezoneInfo.t() | {:error, term()}
get(Timex.Types.valid_timezone(), Timex.Types.valid_datetime()) :: Timex.TimezoneInfo.t() | Timex.AmbiguousTimezoneInfo.t() | {:error, term()}
Gets timezone info for a given zone name and date. The date provided can either be an Erlang datetime tuple, or a DateTime struct, and if one is not provided, then the current date and time is returned.
local()
View Source
local() ::
Timex.TimezoneInfo.t() | Timex.AmbiguousTimezoneInfo.t() | {:error, term()}
local() :: Timex.TimezoneInfo.t() | Timex.AmbiguousTimezoneInfo.t() | {:error, term()}
Gets the local timezone configuration for the current date and time.
local(date)
View Source
local(Timex.Types.valid_datetime()) ::
Timex.TimezoneInfo.t() | Timex.AmbiguousTimezoneInfo.t() | {:error, term()}
local(Timex.Types.valid_datetime()) :: Timex.TimezoneInfo.t() | Timex.AmbiguousTimezoneInfo.t() | {:error, term()}
Gets the local timezone configuration for the provided date and time. The provided date and time can either be an Erlang datetime tuple, or a DateTime struct.
name_of(offset)
View Source
name_of(
Timex.Types.valid_timezone()
| Timex.TimezoneInfo.t()
| Timex.AmbiguousTimezoneInfo.t()
) ::
String.t()
| {:error, {:invalid_timezone, term()}}
| {:error, {:no_such_zone, term()}}
| {:error, term()}
name_of( Timex.Types.valid_timezone() | Timex.TimezoneInfo.t() | Timex.AmbiguousTimezoneInfo.t() ) :: String.t() | {:error, {:invalid_timezone, term()}} | {:error, {:no_such_zone, term()}} | {:error, term()}
This function takes one of the varying timezone representations:
- atoms
- offset integers
- shortcut names (i.e. :utc, :local, "Z", "A")
and resolves the full name of the timezone if it's able.
If a string is provided which isn't recognized, it is returned untouched,
only when get/2
is called will the timezone lookup fail.
resolve(tzname, datetime, utc_or_wall \\ :wall)
View Source
resolve(String.t(), non_neg_integer(), :utc | :wall) ::
Timex.TimezoneInfo.t() | Timex.AmbiguousTimezoneInfo.t() | {:error, term()}
resolve(String.t(), non_neg_integer(), :utc | :wall) :: Timex.TimezoneInfo.t() | Timex.AmbiguousTimezoneInfo.t() | {:error, term()}
Given a timezone name as a string, and a date/time in the form of the number of seconds since year zero, attempt to resolve a TimezoneInfo for that date/time. If the time is ambiguous, AmbiguousTimezoneInfo will be returned. If no result is found, an error will be returned.
If an invalid zone name is provided, an error will be returned
total_offset(timezone_info) View Source
total_offset(std_offset, utc_offset) View Source
tzdata_to_timezone(tzdata, zone)
View Source
tzdata_to_timezone(map(), String.t()) :: Timex.TimezoneInfo.t()
tzdata_to_timezone(map(), String.t()) :: Timex.TimezoneInfo.t()