Skip to content

Fix <time> XML format: use Z suffix instead of +00:00 for UTC #82

@Sibyx

Description

@Sibyx

Problem

DateTimeHelper::formatDateTime() uses PHP's 'c' format (ISO 8601) which outputs UTC timestamps as 2026-03-10T15:22:08+00:00. The GPX specification and XML/ISO 8601 convention prefer Z as the canonical UTC designator:

<!-- Current (2.x) -->
<time>2026-03-10T15:22:08+00:00</time>

<!-- Expected -->
<time>2026-03-10T15:22:08Z</time>

Z is shorter, more standard for GPX/XML, and universally understood.

Related discussion: #67 (comment)

Current code

// src/phpGPX/Helpers/DateTimeHelper.php:23
public static function formatDateTime($datetime, string $format = 'c', ?string $timezone = 'UTC'): ?string

The 'c' format always outputs +00:00 for UTC.

Proposed fix

Use 'Y-m-d\TH:i:sp' as the default format. The p specifier (PHP 8.0+) outputs Z for UTC and ±HH:MM for other timezones — exactly what we need.

public static function formatDateTime($datetime, string $format = 'Y-m-d\TH:i:sp', ?string $timezone = 'UTC'): ?string

Impact

  • All <time> elements in XML output
  • startedAt / finishedAt in JSON serialization
  • Requires PHP >= 8.0 (already satisfied — project requires >= 8.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions