@@ -130,76 +130,6 @@ def _format_offset(off):
130
130
return s
131
131
132
132
133
- # pylint: disable=invalid-name, too-many-locals, too-many-nested-blocks, too-many-branches, too-many-statements
134
- def _wrap_strftime (time_obj , strftime_fmt , timetuple ):
135
- # Don't call utcoffset() or tzname() unless actually needed.
136
- f_replace = None # the string to use for %f
137
- z_replace = None # the string to use for %z
138
- Z_replace = None # the string to use for %Z
139
-
140
- # Scan strftime_fmt for %z and %Z escapes, replacing as needed.
141
- newformat = []
142
- push = newformat .append
143
- i , n = 0 , len (strftime_fmt )
144
- while i < n :
145
- ch = strftime_fmt [i ]
146
- i += 1
147
- if ch == "%" :
148
- if i < n :
149
- ch = strftime_fmt [i ]
150
- i += 1
151
- if ch == "f" :
152
- if f_replace is None :
153
- f_replace = "%06d" % getattr (time_obj , "microsecond" , 0 )
154
- newformat .append (f_replace )
155
- elif ch == "z" :
156
- if z_replace is None :
157
- z_replace = ""
158
- if hasattr (time_obj , "utcoffset" ):
159
- offset = time_obj .utcoffset ()
160
- if offset is not None :
161
- sign = "+"
162
- if offset .days < 0 :
163
- offset = - offset
164
- sign = "-"
165
- h , rest = divmod (offset , timedelta (hours = 1 ))
166
- m , rest = divmod (rest , timedelta (minutes = 1 ))
167
- s = rest .seconds
168
- u = offset .microseconds
169
- if u :
170
- z_replace = "%c%02d%02d%02d.%06d" % (
171
- sign ,
172
- h ,
173
- m ,
174
- s ,
175
- u ,
176
- )
177
- elif s :
178
- z_replace = "%c%02d%02d%02d" % (sign , h , m , s )
179
- else :
180
- z_replace = "%c%02d%02d" % (sign , h , m )
181
- assert "%" not in z_replace
182
- newformat .append (z_replace )
183
- elif ch == "Z" :
184
- if Z_replace is None :
185
- Z_replace = ""
186
- if hasattr (time_obj , "tzname" ):
187
- s = time_obj .tzname ()
188
- if s is not None :
189
- # strftime is going to have at this: escape %
190
- Z_replace = s .replace ("%" , "%%" )
191
- newformat .append (Z_replace )
192
- else :
193
- push ("%" )
194
- push (ch )
195
- else :
196
- push ("%" )
197
- else :
198
- push (ch )
199
- newformat = "" .join (newformat )
200
- return _time .strftime (newformat , timetuple )
201
-
202
-
203
133
# Utility functions - timezone
204
134
def _check_tzname (name ):
205
135
""""Just raise TypeError if the arg isn't None or a string."""
@@ -370,7 +300,7 @@ def _ord2ymd(n):
370
300
class timedelta :
371
301
"""A timedelta object represents a duration, the difference between two dates or times."""
372
302
373
- # pylint: disable=too-many-arguments
303
+ # pylint: disable=too-many-arguments, too-many-locals, too-many-statements
374
304
def __new__ (
375
305
cls ,
376
306
days = 0 ,
@@ -859,13 +789,15 @@ def __new__(cls, offset, name=_Omitted):
859
789
raise ValueError (
860
790
"offset must be a timedelta" " representing a whole number of minutes"
861
791
)
792
+ cls ._offset = offset
793
+ cls ._name = name
862
794
return cls ._create (offset , name )
863
795
864
- # pylint: disable=protected-access
796
+ # pylint: disable=protected-access, bad-super-call
865
797
@classmethod
866
798
def _create (cls , offset , name = None ):
867
799
"""High-level creation for a timezone object."""
868
- self = tzinfo .__new__ (cls )
800
+ self = super ( tzinfo , cls ) .__new__ (cls )
869
801
self ._offset = offset
870
802
self ._name = name
871
803
return self
@@ -998,15 +930,6 @@ def isoformat(self, timespec="auto"):
998
930
# For a time t, str(t) is equivalent to t.isoformat()
999
931
__str__ = isoformat
1000
932
1001
- def strftime (self , fmt ):
1002
- """Format using strftime(). The date part of the timestamp passed
1003
- to underlying strftime should not be used.
1004
- """
1005
- # The year must be >= 1000 else Python's strftime implementation
1006
- # can raise a bogus exception.
1007
- timetuple = (1900 , 1 , 1 , self ._hour , self ._minute , self ._second , 0 , 1 , - 1 )
1008
- return _wrap_strftime (self , fmt , timetuple )
1009
-
1010
933
def utcoffset (self ):
1011
934
"""Return the timezone offset in minutes east of UTC (negative west of
1012
935
UTC)."""
@@ -1123,8 +1046,6 @@ def _tzstr(self, sep=":"):
1123
1046
def __format__ (self , fmt ):
1124
1047
if not isinstance (fmt , str ):
1125
1048
raise TypeError ("must be str, not %s" % type (fmt ).__name__ )
1126
- if len (fmt ) != 0 :
1127
- return self .strftime (fmt )
1128
1049
return str (self )
1129
1050
1130
1051
def __repr__ (self ):
@@ -1259,7 +1180,11 @@ def _fromtimestamp(cls, t, utc, tz):
1259
1180
t -= 1
1260
1181
us += 1000000
1261
1182
1262
- converter = _time .gmtime if utc else _time .localtime
1183
+ if utc :
1184
+ raise NotImplementedError (
1185
+ "CircuitPython does not currently implement time.gmtime."
1186
+ )
1187
+ converter = _time .localtime
1263
1188
struct_time = converter (t )
1264
1189
ss = min (struct_time [5 ], 59 ) # clamp out leap seconds if the platform has them
1265
1190
result = cls (
@@ -1272,39 +1197,7 @@ def _fromtimestamp(cls, t, utc, tz):
1272
1197
us ,
1273
1198
tz ,
1274
1199
)
1275
- if tz is None :
1276
- # As of version 2015f max fold in IANA database is
1277
- # 23 hours at 1969-09-30 13:00:00 in Kwajalein.
1278
- # Let's probe 24 hours in the past to detect a transition:
1279
- max_fold_seconds = 24 * 3600
1280
-
1281
- struct_time = converter (t - max_fold_seconds )[:6 ]
1282
- probe1 = cls (
1283
- struct_time [0 ],
1284
- struct_time [1 ],
1285
- struct_time [2 ],
1286
- struct_time [3 ],
1287
- struct_time [4 ],
1288
- struct_time [5 ],
1289
- us ,
1290
- tz ,
1291
- )
1292
- trans = result - probe1 - timedelta (0 , max_fold_seconds )
1293
- if trans .days < 0 :
1294
- struct_time = converter (t + trans // timedelta (0 , 1 ))[:6 ]
1295
- probe2 = cls (
1296
- struct_time [0 ],
1297
- struct_time [1 ],
1298
- struct_time [2 ],
1299
- struct_time [3 ],
1300
- struct_time [4 ],
1301
- struct_time [5 ],
1302
- us ,
1303
- tz ,
1304
- )
1305
- if probe2 == result :
1306
- result ._fold = 1
1307
- else :
1200
+ if tz is not None :
1308
1201
result = tz .fromutc (result )
1309
1202
return result
1310
1203
@@ -1316,7 +1209,7 @@ def fromtimestamp(cls, timestamp, tz=None):
1316
1209
@classmethod
1317
1210
def now (cls , timezone = None ):
1318
1211
"""Return the current local date and time."""
1319
- return cls .fromtimestamp (_time .time (), timezone )
1212
+ return cls .fromtimestamp (_time .time (), tz = timezone )
1320
1213
1321
1214
@classmethod
1322
1215
def utcfromtimestamp (cls , timestamp ):
@@ -1449,19 +1342,18 @@ def weekday(self):
1449
1342
"""Return the day of the week as an integer, where Monday is 0 and Sunday is 6."""
1450
1343
return (self .toordinal () + 6 ) % 7
1451
1344
1452
- def strftime (self , fmt ):
1453
- """Format using strftime(). The date part of the timestamp passed
1454
- to underlying strftime should not be used.
1455
- """
1456
- # The year must be >= 1000 else Python's strftime implementation
1457
- # can raise a bogus exception.
1458
- timetuple = (1900 , 1 , 1 , self ._hour , self ._minute , self ._second , 0 , 1 , - 1 )
1459
- return _wrap_strftime (self , fmt , timetuple )
1460
-
1461
- def __format__ (self , fmt ):
1462
- if len (fmt ) != 0 :
1463
- return self .strftime (fmt )
1464
- return str (self )
1345
+ def ctime (self ):
1346
+ "Return string representing the datetime."
1347
+ weekday = self .toordinal () % 7 or 7
1348
+ return "%s %s %2d %02d:%02d:%02d %04d" % (
1349
+ _DAYNAMES [weekday ],
1350
+ _MONTHNAMES [self ._month ],
1351
+ self ._day ,
1352
+ self ._hour ,
1353
+ self ._minute ,
1354
+ self ._second ,
1355
+ self ._year ,
1356
+ )
1465
1357
1466
1358
def __repr__ (self ):
1467
1359
"""Convert to formal string, for repr()."""
0 commit comments