def _parse_time(time_str, property_name): """ Parse the time from the given string, convert to UTC, and return the datetime object Parameters ---------- time_str : str The time to parse property_name : str Name of the property where this time came from. Used in the exception raised if time is not parseable Returns ------- datetime.datetime Parsed datetime object Raises ------ samcli.commands.exceptions.UserException If the string cannot be parsed as a timestamp """ if not time_str: return None parsed = parse_date(time_str) if not parsed: raise InvalidTimestampError( "Unable to parse the time provided by '{}'".format( property_name)) return to_utc(parsed)
def test_without_timezone(self): date = parse_date("2018-07-06T13:09:54Z").replace(tzinfo=None) expected = datetime.datetime(2018, 7, 6, 13, 9, 54) result = to_utc(date) self.assertEqual(expected, result)
def test_with_timezone(self): date = parse_date("2018-07-06 13:09:54 PDT") expected = datetime.datetime(2018, 7, 6, 20, 9, 54) result = to_utc(date) self.assertEqual(expected, result)
def test_without_timezone(self): date = parse_date("2018-07-06T13:09:54Z").replace(tzinfo=None) expected = datetime.datetime(2018, 7, 6, 13, 9, 54) result = to_utc(date) self.assertEquals(expected, result)
def test_with_timezone(self): date = parse_date("2018-07-06 13:09:54 PDT") expected = datetime.datetime(2018, 7, 6, 20, 9, 54) result = to_utc(date) self.assertEquals(expected, result)
def _parse_time(time_str, property_name): """ Parse the time from the given string, convert to UTC, and return the datetime object Parameters ---------- time_str : str The time to parse property_name : str Name of the property where this time came from. Used in the exception raised if time is not parseable Returns ------- datetime.datetime Parsed datetime object Raises ------ samcli.commands.exceptions.UserException If the string cannot be parsed as a timestamp """ if not time_str: return parsed = parse_date(time_str) if not parsed: raise UserException("Unable to parse the time provided by '{}'".format(property_name)) return to_utc(parsed)