lair.clock.UTC2MST#
- lair.clock.UTC2MST(x, *, localize=False, driver=None, ambiguous='raise', nonexistent='raise')[source]#
Convert times from UTC to Mountain Standard Time (
'Etc/GMT+7').MST is 7 hours behind UTC all year, with no daylight saving time, so every day is 24 hours long, in every year. The zone is
'Etc/GMT+7', a fixed offset (its sign is POSIX’s, reversed): the tz database’s'MST'is Phoenix’s time, which kept daylight saving time in 1967 and the war years. 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 MST. 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, adatetimeadatetimeand apd.Timestampapd.Timestamp.
See also
UTC2MTNUTC to Salt Lake City time, which follows daylight saving time.
MST2UTCThe way back, from MST to UTC.
convert_timezonesThe general conversion, from any zone to any zone.
Examples
18:00 UTC is 11:00 MST, in January and in July:
>>> import datetime as dt >>> from lair.clock import UTC2MST >>> UTC2MST(dt.datetime(2024, 7, 15, 18)) datetime.datetime(2024, 7, 15, 11, 0, tzinfo=zoneinfo.ZoneInfo(key='Etc/GMT+7'))
The index of a DataFrame, kept naive in MST with
localize=True:>>> import pandas as pd >>> data = pd.DataFrame( ... {"ch4": [2000.0]}, index=pd.to_datetime(["2024-07-15 18:00"]) ... ) >>> UTC2MST(data, localize=True, driver="pandas") ch4 2024-07-15 11:00:00 2000.0