コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
ファイル: test_time.py プロジェクト: Frameio/aws-sam-cli
    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)
コード例 #5
0
ファイル: test_time.py プロジェクト: Frameio/aws-sam-cli
    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)
コード例 #6
0
ファイル: logs_context.py プロジェクト: Frameio/aws-sam-cli
    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)