Skip to content

fix: preserve fractional event timestamps in UTC - #223

Merged
marandaneto merged 3 commits into
mainfrom
fix/preserve-timestamp-precision
Aug 13, 2026
Merged

fix: preserve fractional event timestamps in UTC#223
marandaneto merged 3 commits into
mainfrom
fix/preserve-timestamp-precision

Conversation

@marandaneto

@marandaneto marandaneto commented Aug 13, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

The PHP SDK formats generated event timestamps with second-level precision. Events captured within the same second therefore receive identical timestamps and can appear out of order. The existing fractional timestamp paths also drop fractions from ISO strings and produce an invalid value for microtime(true).

The SDK also formats timestamps in PHP's configured timezone. Malformed timestamp strings fall through to the Unix epoch. These behaviors can make closely spaced events ambiguous in ordered analysis such as funnels.

💚 How did you test it?

  • Ran ./vendor/bin/phpunit test - 450 tests passed with 3,823 assertions.
  • Ran focused tests for generated, microtime(true), ISO, whole-second, non-UTC, and malformed timestamps.
  • Ran PHPCS on the changed PHP files. It reported no errors.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm change to generate a change intent file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Pi coding agent implemented and tested the fix in a dedicated worktree. Pi autoreview checked commit ae98eee against origin/main and reported no actionable findings. The formatter now preserves fractional seconds, emits every timestamp in UTC, and uses the current time instead of the Unix epoch when a timestamp string cannot be parsed.

@marandaneto marandaneto self-assigned this Aug 13, 2026
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

posthog-php Compliance Report

Date: 2026-08-13 17:37:26 UTC
Duration: 95273ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 12ms
Format Validation.Event Has Uuid 6ms
Format Validation.Event Has Lib Properties 6ms
Format Validation.Distinct Id Is String 5ms
Format Validation.Token Is Present 6ms
Format Validation.Custom Properties Preserved 5ms
Format Validation.Event Has Timestamp 6ms
Retry Behavior.Retries On 503 5315ms
Retry Behavior.Does Not Retry On 400 2009ms
Retry Behavior.Does Not Retry On 401 2009ms
Retry Behavior.Respects Retry After Header 8015ms
Retry Behavior.Implements Backoff 15715ms
Retry Behavior.Retries On 500 5115ms
Retry Behavior.Retries On 502 5114ms
Retry Behavior.Retries On 504 5115ms
Retry Behavior.Max Retries Respected 16528ms
Deduplication.Generates Unique Uuids 11ms
Deduplication.Preserves Uuid On Retry 5113ms
Deduplication.Preserves Uuid And Timestamp On Retry 10322ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5117ms
Deduplication.No Duplicate Events In Batch 12ms
Deduplication.Different Events Have Different Uuids 6ms
Compression.Sends Gzip When Enabled 6ms
Batch Format.Uses Proper Batch Structure 6ms
Batch Format.Flush With No Events Sends Nothing 3ms
Batch Format.Multiple Events Batched Together 10ms
Error Handling.Does Not Retry On 403 2007ms
Error Handling.Does Not Retry On 413 2010ms
Error Handling.Retries On 408 5114ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 7ms
Request Payload.Flags Request Uses V2 Query Param 4ms
Request Payload.Flags Request Hits Flags Path Not Decide 5ms
Request Payload.Flags Request Omits Authorization Header 5ms
Request Payload.Token In Flags Body Matches Init 4ms
Request Payload.Groups Round Trip 5ms
Request Payload.Groups Default To Empty Object 7ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 5ms
Request Payload.Disable Geoip Omitted Defaults To False 4ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 5ms
Request Lifecycle.No Flags Request On Init Alone 2ms
Request Lifecycle.No Flags Request On Normal Capture 6ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 7ms
Request Lifecycle.Mock Response Value Is Returned To Caller 5ms
Retry Behavior.Retries Flags On 502 106ms
Retry Behavior.Retries Flags On 504 107ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 8ms

@marandaneto marandaneto changed the title fix: preserve fractional event timestamps fix: preserve fractional event timestamps in UTC Aug 13, 2026
@marandaneto
marandaneto marked this pull request as ready for review August 13, 2026 17:43
@marandaneto
marandaneto requested a review from a team as a code owner August 13, 2026 17:43
@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "fix: avoid epoch fallback for invalid ti..." | Re-trigger Greptile

@marandaneto
marandaneto merged commit 0533b67 into main Aug 13, 2026
24 checks passed
@marandaneto
marandaneto deleted the fix/preserve-timestamp-precision branch August 13, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants