Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/pytz/reference.py
7771 views
'''1Reference tzinfo implementations from the Python docs.2Used for testing against as they are only correct for the years31987 to 2006. Do not use these for real code.4'''56from datetime import tzinfo, timedelta, datetime7from pytz import HOUR, ZERO, UTC89__all__ = [10'FixedOffset',11'LocalTimezone',12'USTimeZone',13'Eastern',14'Central',15'Mountain',16'Pacific',17'UTC'18]192021# A class building tzinfo objects for fixed-offset time zones.22# Note that FixedOffset(0, "UTC") is a different way to build a23# UTC tzinfo object.24class FixedOffset(tzinfo):25"""Fixed offset in minutes east from UTC."""2627def __init__(self, offset, name):28self.__offset = timedelta(minutes=offset)29self.__name = name3031def utcoffset(self, dt):32return self.__offset3334def tzname(self, dt):35return self.__name3637def dst(self, dt):38return ZERO394041import time as _time4243STDOFFSET = timedelta(seconds=-_time.timezone)44if _time.daylight:45DSTOFFSET = timedelta(seconds=-_time.altzone)46else:47DSTOFFSET = STDOFFSET4849DSTDIFF = DSTOFFSET - STDOFFSET505152# A class capturing the platform's idea of local time.53class LocalTimezone(tzinfo):5455def utcoffset(self, dt):56if self._isdst(dt):57return DSTOFFSET58else:59return STDOFFSET6061def dst(self, dt):62if self._isdst(dt):63return DSTDIFF64else:65return ZERO6667def tzname(self, dt):68return _time.tzname[self._isdst(dt)]6970def _isdst(self, dt):71tt = (dt.year, dt.month, dt.day,72dt.hour, dt.minute, dt.second,73dt.weekday(), 0, -1)74stamp = _time.mktime(tt)75tt = _time.localtime(stamp)76return tt.tm_isdst > 07778Local = LocalTimezone()798081def first_sunday_on_or_after(dt):82days_to_go = 6 - dt.weekday()83if days_to_go:84dt += timedelta(days_to_go)85return dt868788# In the US, DST starts at 2am (standard time) on the first Sunday in April.89DSTSTART = datetime(1, 4, 1, 2)90# and ends at 2am (DST time; 1am standard time) on the last Sunday of Oct.91# which is the first Sunday on or after Oct 25.92DSTEND = datetime(1, 10, 25, 1)939495# A complete implementation of current DST rules for major US time zones.96class USTimeZone(tzinfo):9798def __init__(self, hours, reprname, stdname, dstname):99self.stdoffset = timedelta(hours=hours)100self.reprname = reprname101self.stdname = stdname102self.dstname = dstname103104def __repr__(self):105return self.reprname106107def tzname(self, dt):108if self.dst(dt):109return self.dstname110else:111return self.stdname112113def utcoffset(self, dt):114return self.stdoffset + self.dst(dt)115116def dst(self, dt):117if dt is None or dt.tzinfo is None:118# An exception may be sensible here, in one or both cases.119# It depends on how you want to treat them. The default120# fromutc() implementation (called by the default astimezone()121# implementation) passes a datetime with dt.tzinfo is self.122return ZERO123assert dt.tzinfo is self124125# Find first Sunday in April & the last in October.126start = first_sunday_on_or_after(DSTSTART.replace(year=dt.year))127end = first_sunday_on_or_after(DSTEND.replace(year=dt.year))128129# Can't compare naive to aware objects, so strip the timezone from130# dt first.131if start <= dt.replace(tzinfo=None) < end:132return HOUR133else:134return ZERO135136Eastern = USTimeZone(-5, "Eastern", "EST", "EDT")137Central = USTimeZone(-6, "Central", "CST", "CDT")138Mountain = USTimeZone(-7, "Mountain", "MST", "MDT")139Pacific = USTimeZone(-8, "Pacific", "PST", "PDT")140141142