MCPcopy Create free account
hub / github.com/aws/aws-cli / _parse_timestamp_with_tzinfo

Function _parse_timestamp_with_tzinfo

awscli/botocore/utils.py:794–810  ·  view source on GitHub ↗

Parse timestamp with pluggable tzinfo options.

(value, tzinfo)

Source from the content-addressed store, hash-verified

792
793
794def _parse_timestamp_with_tzinfo(value, tzinfo):
795 """Parse timestamp with pluggable tzinfo options."""
796 if isinstance(value, (int, float)):
797 # Possibly an epoch time.
798 return datetime.datetime.fromtimestamp(value, tzinfo())
799 else:
800 try:
801 return datetime.datetime.fromtimestamp(float(value), tzinfo())
802 except (TypeError, ValueError):
803 pass
804 try:
805 # In certain cases, a timestamp marked with GMT can be parsed into a
806 # different time zone, so here we provide a context which will
807 # enforce that GMT == UTC.
808 return dateutil.parser.parse(value, tzinfos={'GMT': tzutc()})
809 except (TypeError, ValueError) as e:
810 raise ValueError(f'Invalid timestamp "{value}": {e}')
811
812
813def parse_timestamp(value):

Callers 1

parse_timestampFunction · 0.85

Calls 2

fromtimestampMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected