Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions datadog_checks_base/changelog.d/25497.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix parsing RFC3339 timestamps with fractional seconds.
2 changes: 1 addition & 1 deletion datadog_checks_base/datadog_checks/base/utils/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse_rfc3339(s):
for x in range(6):
dt[x] = int(groups[x])
if groups[6] is not None:
dt[6] = int(groups[6])
dt[6] = int(groups[6][1:7].ljust(6, '0'))
tz = UTC
if groups[7] is not None and groups[7] != 'Z' and groups[7] != 'z':
tz_groups = _re_timezone.search(groups[7]).groups()
Expand Down
33 changes: 33 additions & 0 deletions datadog_checks_base/tests/base/utils/test_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# (C) Datadog, Inc. 2026-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

from datetime import datetime, timedelta, timezone

import pytest

from datadog_checks.base.utils.date import parse_rfc3339


@pytest.mark.parametrize(
'fraction, microsecond',
[
('', 0),
('.0', 0),
('.1', 100000),
('.123', 123000),
('.001', 1000),
('.123456', 123456),
('.000001', 1),
('.123456789', 123456),
('.999999999', 999999),
('.000000001', 0),
(',123', 123000),
],
)
@pytest.mark.parametrize('suffix, offset', [('Z', 0), ('+05:30', 330), ('-04:30', -270)])
def test_parse_rfc3339_fractional_seconds(fraction: str, microsecond: int, suffix: str, offset: int):
timestamp = f'2019-02-18T16:00:06{fraction}{suffix}'
expected = datetime(2019, 2, 18, 16, 0, 6, microsecond, tzinfo=timezone(timedelta(minutes=offset)))

assert parse_rfc3339(timestamp) == expected
Loading