172172===============
173173
174174An implementation may have additional timezone names that must be injected into
175- th dateutil.gettz() processing.
175+ the ``pendulum`` processing. (Formerly `` dateutil.gettz()``.)
176176
177177For example, there may be the following sequence:
178178
179- 1. A lowercase match for an alias or an existing dateutil timezone.
179+ 1. A lowercase match for an alias or an existing timezone.
180180
181- 2. A titlecase match for an existing dateutil timezone.
181+ 2. A titlecase match for an existing timezone.
182182
1831833. The fallback, which is a +/-HH:MM string.
184184
194194 Optional , Sequence , Tuple , Type , TypeVar , Union , cast ,
195195 overload )
196196
197- import dateutil .parser
198- import dateutil .tz
197+ import pendulum
198+ from pendulum import timezone
199+ import pendulum .tz .exceptions
200+
199201
200202logger = logging .getLogger ("celtypes" )
201203
@@ -1035,12 +1037,12 @@ class TimestampType(datetime.datetime):
10351037 The Joda project (https://www.joda.org/joda-time/timezones.html)
10361038 says "Time zone data is provided by the public IANA time zone database."
10371039
1038- The ``dateutil`` project (https://pypi.org/project/python-dateutil/)
1039- is used for TZ handling and timestamp parsing .
1040+ TZ handling and timestamp parsing is doine with
1041+ the ``pendulum`` (https://pendulum.eustace.io) project .
10401042
10411043 Additionally, there is a ``TZ_ALIASES`` mapping available in this class to permit additional
10421044 timezone names. By default, the mapping is empty, and the only names
1043- available are those recognized by :mod:`dateutil.tz `.
1045+ available are those recognized by :mod:`pendulum.timezone `.
10441046 """
10451047
10461048 TZ_ALIASES : Dict [str , str ] = {}
@@ -1076,7 +1078,7 @@ def __new__(
10761078
10771079 elif isinstance (source , str ):
10781080 # Use dateutil to try a variety of text formats.
1079- parsed_datetime = dateutil . parser . isoparse (source )
1081+ parsed_datetime = cast ( datetime . datetime , pendulum . parse (source ) )
10801082 return super ().__new__ (
10811083 cls ,
10821084 year = parsed_datetime .year ,
@@ -1143,10 +1145,15 @@ def tz_name_lookup(cls, tz_name: str) -> Optional[datetime.tzinfo]:
11431145 Tweak ``celpy.celtypes.TimestampType.TZ_ALIASES``.
11441146 """
11451147 tz_lookup = str (tz_name )
1148+ tz : Optional [datetime .tzinfo ]
11461149 if tz_lookup in cls .TZ_ALIASES :
1147- tz = dateutil . tz . gettz (cls .TZ_ALIASES [tz_lookup ])
1150+ tz = timezone (cls .TZ_ALIASES [tz_lookup ])
11481151 else :
1149- tz = dateutil .tz .gettz (tz_lookup )
1152+ try :
1153+ tz = cast (datetime .tzinfo , timezone (tz_lookup ))
1154+ except pendulum .tz .exceptions .InvalidTimezone :
1155+ # ±hh:mm format...
1156+ tz = cls .tz_offset_parse (tz_name )
11501157 return tz
11511158
11521159 @classmethod
@@ -1165,11 +1172,9 @@ def tz_offset_parse(cls, tz_name: str) -> Optional[datetime.tzinfo]:
11651172 def tz_parse (tz_name : Optional [str ]) -> Optional [datetime .tzinfo ]:
11661173 if tz_name :
11671174 tz = TimestampType .tz_name_lookup (tz_name )
1168- if tz is None :
1169- tz = TimestampType .tz_offset_parse (tz_name )
11701175 return tz
11711176 else :
1172- return dateutil . tz . UTC
1177+ return timezone ( " UTC" )
11731178
11741179 def getDate (self , tz_name : Optional [StringType ] = None ) -> IntType :
11751180 new_tz = self .tz_parse (tz_name )
0 commit comments