Skip to content

Aware datetime offsets are lost in SLO history timestamp conversion #1013

Open

Description

@student-shivamm

Describe the bug

force_to_epoch_seconds() ignores aware datetime offsets. This affects the
time-range parameters built by ServiceLevelObjective.history() and conversion
of datetime inputs through parse_date_as_epoch_timestamp().

To Reproduce

from datetime import datetime, timedelta, timezone
from datadog.util.format import force_to_epoch_seconds

utc = datetime(2024, 1, 1, tzinfo=timezone.utc)
india = datetime(2024, 1, 1, 5, 30, tzinfo=timezone(timedelta(hours=5, minutes=30)))
print(force_to_epoch_seconds(utc))    # 1704067200
print(force_to_epoch_seconds(india))  # 1704087000

Expected behavior

These represent the same instant; both should return 1704067200. Currently the
helper passes the local wall-clock tuple to calendar.timegm, losing the offset.

Environment and Versions

datadog 0.55.0 from main a483dd9; Windows / Python 3.12.14.

Additional context

A local change using utctimetuple preserves existing naive-UTC, numeric and
whole-second behavior. Ten new failing cases become passing; 96 focused
utility/mocked API tests pass. Broader import-isolation failures and native
Windows typing findings are also reproduced upstream. No live Datadog service
was contacted. A focused patch and tests are prepared if this approach is welcome.

Prepared and locally validated with OpenAI Codex assistance. No production
incident or independent human review claimed. Severity/triage left to maintainers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions