Skip to content

Bug: DATETIME_FORMAT_V2 hardcodes +0000 timezone, losing timezone information #38

@hh1985

Description

@hh1985

Problem

The DATETIME_FORMAT_V2 constant in constants.py hardcodes +0000 (UTC) as the timezone suffix:

DATETIME_FORMAT_V2 = "%Y-%m-%dT%H:%M:%S.000+0000"

This causes timezone information to be lost when formatting datetime objects with non-UTC timezones.

Impact

When creating/updating tasks with a timezone-aware datetime (e.g., Shanghai timezone +08:00), the formatted string incorrectly shows +0000 instead of the actual timezone offset. This can lead to incorrect date display in the TickTick/Dida365 app.

Example

from datetime import datetime
from zoneinfo import ZoneInfo
from ticktick_sdk.models.base import TickTickModel

shanghai_tz = ZoneInfo('Asia/Shanghai')
dt = datetime(2026, 3, 24, 0, 0, 0, tzinfo=shanghai_tz)

formatted = TickTickModel.format_datetime(dt, "v2")
# Current output: 2026-03-24T00:00:00.000+0000  ❌ Wrong timezone!
# Expected output: 2026-03-24T00:00:00.000+0800  ✅ Correct timezone!

Root Cause

The format string uses a hardcoded +0000 literal instead of the %z format specifier.

Proposed Fix

Change line 232 in ticktick_sdk/constants.py:

# Before
DATETIME_FORMAT_V2 = "%Y-%m-%dT%H:%M:%S.000+0000"

# After
DATETIME_FORMAT_V2 = "%Y-%m-%dT%H:%M:%S.000%z"

The %z specifier will output the correct timezone offset (e.g., +0800, +0000, -0500).

Verification

After applying this fix:

dt = datetime(2026, 3, 24, 0, 0, 0, tzinfo=shanghai_tz)
formatted = TickTickModel.format_datetime(dt, "v2")
# Output: 2026-03-24T00:00:00.000+0800  ✅

The task will now be created with the correct timezone information, and the date will display correctly in the user's timezone.

Environment

  • ticktick-sdk version: 0.4.3
  • Python version: 3.14
  • Platform: macOS
  • Host: dida365.com (Chinese version)

Thank you for this excellent SDK!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions