lair.clock.UTC2MTN#

lair.clock.UTC2MTN(x, *, localize=False, driver=None, ambiguous='raise', nonexistent='raise')[source]#

Convert times from UTC to Salt Lake City time ('America/Denver').

The result follows daylight saving time: 6 hours behind UTC in summer, 7 in winter. A time without a time zone is taken as UTC (the rule on the clock example), and a time with one is converted from its own.

Parameters:
  • x (dt.datetime | pd.Timestamp | list[dt.datetime] | pd.DataFrame | pd.Series) – The times: a single time, a list of them, or with driver='pandas' the index of a DataFrame or the values of a Series.

  • localize (bool, optional) – If True, drop the time zone from the result and keep the clock time in Salt Lake City. Default False.

  • driver (None | 'pandas', optional) – 'pandas' for a DataFrame or Series; None for a single time or a list.

  • ambiguous (optional) – As in convert_timezones(). UTC has no repeated or skipped hours, so they never apply; every shortcut takes them.

  • nonexistent (optional) – As in convert_timezones(). UTC has no repeated or skipped hours, so they never apply; every shortcut takes them.

Returns:

dt.datetime | pd.Timestamp | list[dt.datetime] | pd.DataFrame | pd.Series – The converted times, in the shape of x: a single time gives a single time, a datetime a datetime and a pd.Timestamp a pd.Timestamp.

See also

UTC2MST

UTC to Mountain Standard Time, with no daylight saving time.

MTN2UTC

The way back, from Salt Lake City time to UTC.

convert_timezones

The general conversion, from any zone to any zone.

Examples

18:00 UTC in July is 12:00 daylight time:

>>> import datetime as dt
>>> from lair.clock import UTC2MTN
>>> UTC2MTN(dt.datetime(2024, 7, 15, 18))
datetime.datetime(2024, 7, 15, 12, 0, tzinfo=zoneinfo.ZoneInfo(key='America/Denver'))

A pd.Timestamp gives a pd.Timestamp:

>>> import pandas as pd
>>> UTC2MTN(pd.Timestamp("2024-07-15 18:00"))
Timestamp('2024-07-15 12:00:00-0600', tz='America/Denver')

The index of a DataFrame, kept naive in local time with localize=True:

>>> data = pd.DataFrame(
...     {"ch4": [2000.0]}, index=pd.to_datetime(["2024-07-15 18:00"])
... )
>>> UTC2MTN(data, localize=True, driver="pandas")
                        ch4
2024-07-15 12:00:00  2000.0