Repository navigation
fix: send property date values in UTC - #372
Conversation
posthog-ruby-sync Compliance ReportDate: 2026-11-24T15:46:22.420905+00:00 ✅ All Tests Passed!47/47 tests passed Capture Tests✅ 30/30 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
posthog-ruby-async Compliance ReportDate: 2026-11-24T15:46:16.590395+00:00 ✅ All Tests Passed!47/47 tests passed Capture Tests✅ 30/30 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
SDK performance: posthog-rubyBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
dustinbyrne
left a comment
There was a problem hiding this comment.
Looks good to me — cleanly removes the Rails 7.x/8.0 DateTime#to_time deprecation warning and TZ-dependent formatting while keeping Time, ActiveSupport::TimeWithZone, and DateTime consistent in UTC Z with 3 truncated fractional digits. Verified locally across plain Ruby and ActiveSupport 7.2 / 8.0 / 8.1 and checked backend property-defs-rs + HogQL parsing.
Left one minor wording suggestion on the changeset for rendered email templates.
AI-assisted review.
💡 Motivation and Context
Every RSpec and Logs integration job in CI prints this once, and customers on Rails 7.x see it in their own logs:
PostHog::Utils.datetime_in_iso8601convertedDateTimewithdatetime.to_time, which ActiveSupport overrides. The string therefore depended on the Rails version,to_time_preserves_timezoneand the server'sTZ, and Rails 8 would change it silently.The helper now writes every date-time type as UTC with a
Zsuffix:DateTime: formatted directly withnew_offset(0).strftime('%Y-%m-%dT%H:%M:%S.%LZ'), withoutto_time.TimeandActiveSupport::TimeWithZone:time_in_iso8601(value.getutc), the path the envelopetimestampalready uses.Date: unchanged (%F).The helper is kept because without it JSON encoding decides the format (
"2026-11-23 10:30:15 +0530"in plain Ruby, which isn't ISO 8601, and app-dependent with ActiveSupport). The SDK doesn't setActiveSupport.to_time_preserves_timezone, because that setting applies to the whole app.Before / after
DateTime.new(2026, 11, 23, 10, 30, 15.123456r, '+05:30')with ActiveSupport 7.2. All rows are the same moment:2026-11-23T10:30:15.123+05:302026-11-23T05:00:15.123ZTZ=UTC2026-11-23T05:00:15.123+00:00plus the warning2026-11-23T05:00:15.123ZTZ=America/New_York2026-11-23T00:00:15.123-05:00plus the warning2026-11-23T05:00:15.123Zto_time_preserves_timezone = :zone, or Rails 82026-11-23T10:30:15.123+05:302026-11-23T05:00:15.123ZTimeandTimeWithZonevalues used to keep the caller's offset (10:30:15.123+05:30); they now also come out as05:00:15.123Z.Customer-visible effect
The moment in time stays the same, but the string changes. A
Timeproperty sent as...+05:30today now arrives as...Z. This affects capture, identify and group identify properties and transactional emailtemplate_data. PostHog parses both forms, so filters and breakdowns behave the same. Anything that uses the raw string sees a different value: abefore_sendhook or downstream export that compares it, or an email template that prints the variable without formatting it (for example{{ variables.renews_at }}). This ships as a patch with a changeset that says so.Spec
capture/spec.md(step 5 and "Timestamps on capture v1") requires the event envelopetimestampto be ISO 8601 and normalized to UTC. The spec does not say how date values inside properties are formatted. This change makes property dates follow the envelope rule and posthog-js (toISOString()is always UTC); no spec requires it. Microsecond precision, which the compliance report flags separately, is out of scope and stays truncated to 3 digits.💚 How did you test it?
spec/posthog/utils_spec.rbcoverage: a non-UTCDateTime(UTC +Z, 3 truncated digits), non-UTCTimeandTimeWithZone, UTCDateTime/Time,Dateunchanged. Subprocess runs withTZset toUTC,America/New_YorkandAsia/Tokyo, with and without ActiveSupport, assert the same output and noDEPRECATION WARNINGon stderr. All six new examples failed onmainbefore the fix.client_spec.rb"does not normalize arbitrary Time properties to UTC" (added in fix: normalize SDK timestamps to UTC #248 to keep that PR's scope to the envelope) to expect the UTC form.bundle exec rspec(2595 examples, 0 failures, 49 pending; the output no longer contains theto_timewarning),bundle exec rubocop,bundle exec rake public_api:check.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Zfor every date-time type, keep the helper, don't touchto_time_preserves_timezone). The agent wrote failing specs first, then implemented the fix.