MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / tzinfo_from_match

Function tzinfo_from_match

suds/sax/date.py:418–450  ·  view source on GitHub ↗

Create a timezone information object from a regular expression match. The regular expression match is expected to be from RE_DATE, RE_TIME or RE_DATETIME. @param match_object: The regular expression match. @type value: B{re}.I{MatchObject} @return: A timezone information object

(match_object)

Source from the content-addressed store, hash-verified

416
417
418def tzinfo_from_match(match_object):
419 """Create a timezone information object from a regular expression match.
420
421 The regular expression match is expected to be from RE_DATE, RE_TIME or
422 RE_DATETIME.
423
424 @param match_object: The regular expression match.
425 @type value: B{re}.I{MatchObject}
426 @return: A timezone information object.
427 @rtype: B{datetime}.I{tzinfo}
428
429 """
430 tz_utc = match_object.group('tz_utc')
431 tz_sign = match_object.group('tz_sign')
432 tz_hour = int(match_object.group('tz_hour') or 0)
433 tz_minute = int(match_object.group('tz_minute') or 0)
434 tz_second = int(match_object.group('tz_second') or 0)
435
436 tzinfo = None
437 if tz_utc is not None:
438 tzinfo = UtcTimezone()
439 elif tz_sign is not None:
440 tz_delta = datetime.timedelta(hours=tz_hour,
441 minutes=tz_minute,
442 seconds=tz_second)
443 if tz_delta == datetime.timedelta():
444 tzinfo = UtcTimezone()
445 else:
446 tz_multiplier = int('%s1' % (tz_sign, ))
447 tz_delta = tz_multiplier * tz_delta
448 tzinfo = FixedOffsetTimezone(tz_delta)
449
450 return tzinfo

Callers 2

parseMethod · 0.85
parseMethod · 0.85

Calls 2

UtcTimezoneClass · 0.85
FixedOffsetTimezoneClass · 0.85

Tested by

no test coverage detected