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

Method parse

src/dateutil/parser/_parser.py:1390–1579  ·  view source on GitHub ↗
(self, tzstr)

Source from the content-addressed store, hash-verified

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
1429 setattr(res, offattr, (int(l[i][:2]) * 3600 +
1430 int(l[i][2:]) * 60) * signal)
1431 elif i + 1 < len_l and l[i + 1] == ':':
1432 # -03:00
1433 setattr(res, offattr,
1434 (int(l[i]) * 3600 +
1435 int(l[i + 2]) * 60) * signal)
1436 used_idxs.append(i)
1437 i += 2
1438 elif len_li <= 2:
1439 # -[0]3
1440 setattr(res, offattr,
1441 int(l[i][:2]) * 3600 * signal)
1442 else:
1443 return None
1444 used_idxs.append(i)
1445 i += 1
1446 if res.dstabbr:
1447 break

Callers

nothing calls this directly

Calls 3

splitMethod · 0.80
appendMethod · 0.80
countMethod · 0.80

Tested by

no test coverage detected