MCPcopy Create free account
hub / github.com/dateutil/dateutil / _zi_until

Function _zi_until

tests/test_tzpath_data.py:230–258  ·  view source on GitHub ↗

The approximate UTC timestamp of an UNTIL column.

(fields)

Source from the content-addressed store, hash-verified

228
229
230def _zi_until(fields):
231 """The approximate UTC timestamp of an UNTIL column."""
232 year = int(fields[0])
233 month = _zi_lookup(fields[1], _ZI_MONTHS) + 1 if len(fields) > 1 else 1
234 day = 1
235 if len(fields) > 2:
236 day_spec = fields[2]
237 days_in_month = calendar.monthrange(year, month)[1]
238 if day_spec.startswith("last"):
239 weekday = _zi_lookup(day_spec[4:], _ZI_WEEKDAYS)
240 day = max(
241 d
242 for d in range(1, days_in_month + 1)
243 if calendar.weekday(year, month, d) == weekday
244 )
245 elif ">=" in day_spec or "<=" in day_spec:
246 op = ">=" if ">=" in day_spec else "<="
247 name, first = day_spec.split(op)
248 weekday = _zi_lookup(name, _ZI_WEEKDAYS)
249 step = 1 if op == ">=" else -1
250 day = int(first)
251 while calendar.weekday(year, month, day) != weekday:
252 day += step
253 else:
254 day = int(day_spec)
255
256 seconds = _zi_seconds(fields[3].rstrip("wsugz")) if len(fields) > 3 else 0
257 days = (datetime(year, month, 1) - datetime(1970, 1, 1)).days + day - 1
258 return days * 86400 + seconds
259
260
261def _parse_tzdata_zi(path):

Callers 1

_parse_tzdata_ziFunction · 0.85

Calls 4

_zi_lookupFunction · 0.85
_zi_secondsFunction · 0.85
weekdayMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected