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

Class _tzparser

src/dateutil/parser/_parser.py:1371–1579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1369
1370
1371class _tzparser(object):
1372
1373 class _result(_resultbase):
1374
1375 __slots__ = ["stdabbr", "stdoffset", "dstabbr", "dstoffset",
1376 "start", "end"]
1377
1378 class _attr(_resultbase):
1379 __slots__ = ["month", "week", "weekday",
1380 "yday", "jyday", "day", "time"]
1381
1382 def __repr__(self):
1383 return self._repr("")
1384
1385 def __init__(self):
1386 _resultbase.__init__(self)
1387 self.start = self._attr()
1388 self.end = self._attr()
1389
1390 def parse(self, tzstr):
1391 res = self._result()
1392 l = [x for x in re.split(r'([,:.]|[a-zA-Z]+|[0-9]+)',tzstr) if x]
1393 used_idxs = list()
1394 try:
1395
1396 len_l = len(l)
1397
1398 i = 0
1399 while i < len_l:
1400 # BRST+3[BRDT[+2]]
1401 j = i
1402 while j < len_l and not [x for x in l[j]
1403 if x in "0123456789:,-+"]:
1404 j += 1
1405 if j != i:
1406 if not res.stdabbr:
1407 offattr = "stdoffset"
1408 res.stdabbr = "".join(l[i:j])
1409 else:
1410 offattr = "dstoffset"
1411 res.dstabbr = "".join(l[i:j])
1412
1413 for ii in range(j):
1414 used_idxs.append(ii)
1415 i = j
1416 if (i < len_l and (l[i] in ('+', '-') or l[i][0] in
1417 "0123456789")):
1418 if l[i] in ('+', '-'):
1419 # Yes, that's right. See the TZ variable
1420 # documentation.
1421 signal = (1, -1)[l[i] == '+']
1422 used_idxs.append(i)
1423 i += 1
1424 else:
1425 signal = -1
1426 len_li = len(l[i])
1427 if len_li == 4:
1428 # -0300

Callers 3

_parser.pyFile · 0.85

Calls

no outgoing calls

Tested by 2