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

Method parse

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

Source from the content-addressed store, hash-verified

1382 self.end = self._attr()
1383
1384 def parse(self, tzstr):
1385 res = self._result()
1386 l = [x for x in re.split(r'([,:.]|[a-zA-Z]+|[0-9]+)',tzstr) if x]
1387 used_idxs = list()
1388 try:
1389
1390 len_l = len(l)
1391
1392 i = 0
1393 while i < len_l:
1394 # BRST+3[BRDT[+2]]
1395 j = i
1396 while j < len_l and not [x for x in l[j]
1397 if x in "0123456789:,-+"]:
1398 j += 1
1399 if j != i:
1400 if not res.stdabbr:
1401 offattr = "stdoffset"
1402 res.stdabbr = "".join(l[i:j])
1403 else:
1404 offattr = "dstoffset"
1405 res.dstabbr = "".join(l[i:j])
1406
1407 for ii in range(j):
1408 used_idxs.append(ii)
1409 i = j
1410 if (i < len_l and (l[i] in ('+', '-') or l[i][0] in
1411 "0123456789")):
1412 if l[i] in ('+', '-'):
1413 # Yes, that's right. See the TZ variable
1414 # documentation.
1415 signal = (1, -1)[l[i] == '+']
1416 used_idxs.append(i)
1417 i += 1
1418 else:
1419 signal = -1
1420 len_li = len(l[i])
1421 if len_li == 4:
1422 # -0300
1423 setattr(res, offattr, (int(l[i][:2]) * 3600 +
1424 int(l[i][2:]) * 60) * signal)
1425 elif i + 1 < len_l and l[i + 1] == ':':
1426 # -03:00
1427 setattr(res, offattr,
1428 (int(l[i]) * 3600 +
1429 int(l[i + 2]) * 60) * signal)
1430 used_idxs.append(i)
1431 i += 2
1432 elif len_li <= 2:
1433 # -[0]3
1434 setattr(res, offattr,
1435 int(l[i][:2]) * 3600 * signal)
1436 else:
1437 return None
1438 used_idxs.append(i)
1439 i += 1
1440 if res.dstabbr:
1441 break

Callers

nothing calls this directly

Calls 3

splitMethod · 0.80
appendMethod · 0.80
countMethod · 0.80

Tested by

no test coverage detected