當前位置: 首頁>>代碼示例>>Python>>正文


Python ciso8601.parse_datetime方法代碼示例

本文整理匯總了Python中ciso8601.parse_datetime方法的典型用法代碼示例。如果您正苦於以下問題:Python ciso8601.parse_datetime方法的具體用法?Python ciso8601.parse_datetime怎麽用?Python ciso8601.parse_datetime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ciso8601的用法示例。


在下文中一共展示了ciso8601.parse_datetime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_invalid_tz_offsets_too_large

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_invalid_tz_offsets_too_large(self):
        # The Python interpreter crashes if you give the datetime constructor a TZ offset with an absolute value >= 1440
        # TODO: Determine whether these are valid ISO 8601 values and therefore whether ciso8601 should support them.
        self.assertRaisesRegex(
            ValueError,
            # Error message differs whether or not we are using pytz or datetime.timezone
            r"^offset must be a timedelta strictly between" if sys.version_info.major >= 3 else r"\('absolute offset is too large', -5940\)",
            ciso8601.parse_datetime,
            '2018-01-01T00:00:00.00-99',
        )

        self.assertRaisesRegex(
            ValueError,
            r"tzminute must be in 0..59",
            ciso8601.parse_datetime,
            '2018-01-01T00:00:00.00-23:60',
        ) 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:19,代碼來源:tests.py

示例2: test_mixed_basic_and_extended_formats

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_mixed_basic_and_extended_formats(self):
        """
        Both dates and times have "basic" and "extended" formats.
        But when you combine them into a datetime, the date and time components
        must have the same format.
        """
        self.assertRaisesRegex(
            ValueError,
            r"Cannot combine \"extended\" date format with \"basic\" time format",
            ciso8601.parse_datetime,
            '2014-01-02T010203',
        ),

        self.assertRaisesRegex(
            ValueError,
            r"Cannot combine \"basic\" date format with \"extended\" time format",
            ciso8601.parse_datetime,
            '20140102T01:02:03',
        ) 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:21,代碼來源:tests.py

示例3: test_valid_rfc3339_timestamps

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_valid_rfc3339_timestamps(self):
        """
        Validate that valid RFC 3339 datetimes are parseable by parse_rfc3339
        and produce the same result as parse_datetime.
        """
        for string in [
                '2018-01-02T03:04:05Z',
                '2018-01-02t03:04:05z',
                '2018-01-02 03:04:05z',
                '2018-01-02T03:04:05+00:00',
                '2018-01-02T03:04:05-00:00',
                '2018-01-02T03:04:05.12345Z',
                '2018-01-02T03:04:05+01:23',
                '2018-01-02T03:04:05-12:34',
                '2018-01-02T03:04:05-12:34',
        ]:
            self.assertEqual(ciso8601.parse_datetime(string),
                             ciso8601.parse_rfc3339(string)) 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:20,代碼來源:tests.py

示例4: _should_process_row

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def _should_process_row(self, row, date_column, is_full_month, is_finalized=None):
        """Determine if we want to process this row.

        Args:
            row (dict): The line item entry from the AWS report file
            date_column (str): The name of date column to check
            is_full_month (boolean): If this is the first time we've processed this bill

        Kwargs:
            is_finalized (boolean): If this is a finalized bill

        Returns:
            (bool): Whether this row should be processed

        """
        if is_finalized or is_full_month:
            return True
        row_date = ciso8601.parse_datetime(row[date_column]).date()
        if row_date < self.data_cutoff_date:
            return False
        return True 
開發者ID:project-koku,項目名稱:koku,代碼行數:23,代碼來源:report_processor_base.py

示例5: convert_date

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def convert_date(self, date_string):
        """Converts date from string format to date object, for use by DateField."""
        if date_string:
            try:
                # TODO: for now, return as a string.
                # When actually supporting DateField, then switch back to date.
                # ciso8601.parse_datetime(ts).astimezone(pytz.utc).date().isoformat()
                return self.date_field_for_converting.deserialize_from_string(date_string).isoformat()
            except ValueError:
                self.incr_counter(self.counter_category_name, 'Cannot convert to date', 1)
                # Don't bother to make sure we return a good value
                # within the interval, so we can find the output for
                # debugging.  Should not be necessary, as this is only
                # used for the column value, not the partitioning.
                return u"BAD: {}".format(date_string)
                # return self.lower_bound_date_string
        else:
            self.incr_counter(self.counter_category_name, 'Missing date', 1)
            return date_string 
開發者ID:edx,項目名稱:edx-analytics-pipeline,代碼行數:21,代碼來源:load_internal_reporting_events.py

示例6: test_problem_check

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_problem_check(self):
        template = self.event_templates['problem_check']
        event = self.create_event_log_line(template=template)
        expected_key = (self.DEFAULT_DATE, self.task.PROJECT_NAME)
        expected_dict = {
            'input_file': '',
            'source': self.task.PROJECT_NAME,
            'event_type': 'problem_check',
            'emitter_type': 'server',
            'timestamp': ciso8601.parse_datetime('2013-12-17T15:38:32.805444+00:00'),
            'received_at': ciso8601.parse_datetime('2013-12-17T15:38:32.805444+00:00'),
            'date': datetime.date(*[int(x) for x in self.DEFAULT_DATE.split('-')]),
            'username': 'test_user',
            'course_id': self.encoded_course_id,
            'org_id': self.encoded_org_id,
            'user_id': '10',
            'raw_event': self.get_raw_event(event),
        }
        expected_value = JsonEventRecord(**expected_dict).to_separated_values()
        self.assert_single_map_output(event, expected_key, expected_value) 
開發者ID:edx,項目名稱:edx-analytics-pipeline,代碼行數:22,代碼來源:test_load_internal_reporting_events.py

示例7: test_android_screen

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_android_screen(self):
        template = self.event_templates['android_screen']
        event = self.create_event_log_line(template=template)
        expected_key = (self.DEFAULT_DATE, self.DEFAULT_PROJECT)
        expected_dict = {
            'input_file': '',
            'source': self.DEFAULT_PROJECT,
            'event_type': 'screen',
            'emitter_type': 'server',
            'timestamp': ciso8601.parse_datetime('2013-12-17T15:38:32.700000+00:00'),
            'received_at': ciso8601.parse_datetime('2013-12-17T15:38:32.796000+00:00'),
            'date': datetime.date(*[int(x) for x in self.DEFAULT_DATE.split('-')]),
            'agent_type': 'tablet',
            'agent_device_name': 'Samsung SM-N920A',
            'agent_os': 'Android',
            'agent_browser': 'Android',
            'agent_touch_capable': True,
            'anonymous_id': self.DEFAULT_ANONYMOUS_ID,
            'category': 'screen',
            'label': 'Launch\\0',
            'raw_event': self.get_raw_event(event),
        }
        expected_value = JsonEventRecord(**expected_dict).to_separated_values()
        self.assert_single_map_output(event, expected_key, expected_value) 
開發者ID:edx,項目名稱:edx-analytics-pipeline,代碼行數:26,代碼來源:test_load_internal_reporting_events.py

示例8: test_auto_generated_valid_formats

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_auto_generated_valid_formats(self):
        for (timestamp, expected_datetime) in generate_valid_timestamp_and_datetime():
            try:
                self.assertEqual(ciso8601.parse_datetime(timestamp), expected_datetime)
            except Exception:
                print("Had problems parsing: {timestamp}".format(timestamp=timestamp))
                raise 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:9,代碼來源:tests.py

示例9: test_excessive_subsecond_precision

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_excessive_subsecond_precision(self):
        self.assertEqual(
            ciso8601.parse_datetime('20140203T103527.234567891234'),
            datetime.datetime(2014, 2, 3, 10, 35, 27, 234567)
        ) 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:7,代碼來源:tests.py

示例10: test_leap_year

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_leap_year(self):
        # There is nothing unusual about leap years in ISO 8601.
        # We just want to make sure that they work in general.
        for leap_year in (1600, 2000, 2016):
            self.assertEqual(
                ciso8601.parse_datetime('{}-02-29'.format(leap_year)),
                datetime.datetime(leap_year, 2, 29, 0, 0, 0, 0)
            ) 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:10,代碼來源:tests.py

示例11: test_special_midnight

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_special_midnight(self):
        self.assertEqual(
            ciso8601.parse_datetime('2014-02-03T24:00:00'),
            datetime.datetime(2014, 2, 4, 0, 0, 0)
        ) 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:7,代碼來源:tests.py

示例12: test_parse_auto_generated_invalid_formats

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_parse_auto_generated_invalid_formats(self):
        for timestamp in generate_invalid_timestamp():
            try:
                with self.assertRaises(ValueError, msg="Timestamp '{0}' was supposed to be invalid, but parsing it didn't raise ValueError.".format(timestamp)):
                    ciso8601.parse_datetime(timestamp)
            except Exception as exc:
                print("Timestamp '{0}' was supposed to raise ValueError, but raised {1} instead".format(timestamp, type(exc).__name__))
                raise 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:10,代碼來源:tests.py

示例13: test_invalid_calendar_separator

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_invalid_calendar_separator(self):
        self.assertRaisesRegex(
            ValueError,
            r"Invalid character while parsing month",
            ciso8601.parse_datetime,
            '2018=01=01',
        )

        self.assertRaisesRegex(
            ValueError,
            r"Invalid character while parsing date separator \('-'\) \('=', Index: 7\)",
            ciso8601.parse_datetime,
            '2018-01=01',
        )

        self.assertRaisesRegex(
            ValueError,
            r"Invalid character while parsing date separator \('-'\) \('0', Index: 7\)",
            ciso8601.parse_datetime,
            '2018-0101',
        )

        self.assertRaisesRegex(
            ValueError,
            r"Invalid character while parsing day \('-', Index: 6\)",
            ciso8601.parse_datetime,
            '201801-01',
        ) 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:30,代碼來源:tests.py

示例14: test_invalid_day_for_month

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_invalid_day_for_month(self):
        for non_leap_year in (1700, 1800, 1900, 2014):
            self.assertRaisesRegex(
                ValueError,
                r"day is out of range for month",
                ciso8601.parse_datetime,
                '{}-02-29'.format(non_leap_year)
            )

        self.assertRaisesRegex(
            ValueError,
            r"day is out of range for month",
            ciso8601.parse_datetime,
            '2014-01-32',
        )

        self.assertRaisesRegex(
            ValueError,
            r"day is out of range for month",
            ciso8601.parse_datetime,
            '2014-06-31',
        )

        self.assertRaisesRegex(
            ValueError,
            r"day is out of range for month",
            ciso8601.parse_datetime,
            '2014-06-00',
        ) 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:31,代碼來源:tests.py

示例15: test_invalid_yyyymm_format

# 需要導入模塊: import ciso8601 [as 別名]
# 或者: from ciso8601 import parse_datetime [as 別名]
def test_invalid_yyyymm_format(self):
        self.assertRaisesRegex(
            ValueError,
            r"Unexpected end of string while parsing day. Expected 2 more characters",
            ciso8601.parse_datetime,
            '201406',
        ) 
開發者ID:closeio,項目名稱:ciso8601,代碼行數:9,代碼來源:tests.py


注:本文中的ciso8601.parse_datetime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。