lair.clock.MST2UTC#

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

Convert times from Mountain Standard Time ('Etc/GMT+7') to UTC.

Use it for a file whose times are standard time all year (its manual or settings say so): MST has no daylight saving time, so no time is repeated or skipped. A time without a time zone is taken as MST, UTC-7 in every year (see UTC2MST()), 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 UTC clock time. 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(). MST has no repeated or skipped hours, so they never apply; every shortcut takes them.

  • nonexistent (optional) – As in convert_timezones(). MST 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

MTN2UTC

The same from Salt Lake City time, which follows daylight saving time.

UTC2MST

The way back, from UTC to MST.

convert_timezones

The general conversion, from any zone to any zone.

Examples

11:00 MST is 18:00 UTC:

>>> import datetime as dt
>>> from lair.clock import MST2UTC
>>> MST2UTC(dt.datetime(2024, 7, 15, 11))
datetime.datetime(2024, 7, 15, 18, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC'))

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

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