:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogvm): use real zone offsets in python hogvm dates (#127436)
Chris Shine368afb36337d
diff --git a/common/hogvm/__tests__/__snapshots__/date.hoge b/common/hogvm/__tests__/__snapshots__/date.hogeindex ab77e9efa77b..96bca684246a 100644--- a/common/hogvm/__tests__/__snapshots__/date.hoge+++ b/common/hogvm/__tests__/__snapshots__/date.hoge@@ -1,15 +1,16 @@["_H", 1, 33, 1234334543, 2, "fromUnixTimestamp", 1, 36, 0, 2, "print", 1, 35, 36, 0, 2, "toString", 1, 2, "print", 1,35, 36, 0, 2, "toUnixTimestamp", 1, 2, "toInt", 1, 2, "print", 1, 35, 32, "-", 2, "print", 1, 35, 32, "2024-05-03", 2,"toDate", 1, 36, 1, 2, "print", 1, 35, 36, 1, 2, "toString", 1, 2, "print", 1, 35, 36, 1, 2, "toUnixTimestamp", 1, 2,-"toInt", 1, 2, "print", 1, 35, 32, "-", 2, "print", 1, 35, 32, "2024-05-03T12:34:56Z", 2, "toDateTime", 1, 36, 2, 2,-"print", 1, 35, 36, 2, 2, "toString", 1, 2, "print", 1, 35, 36, 2, 2, "toUnixTimestamp", 1, 2, "toInt", 1, 2, "print",-1, 35, 32, "------", 2, "print", 1, 35, 36, 2, 32, "Europe/Brussels", 2, "toTimeZone", 2, 2, "print", 1, 35, 36, 2, 32,-"Europe/Brussels", 2, "toTimeZone", 2, 2, "toString", 1, 2, "print", 1, 35, 32, "-", 2, "print", 1, 35, 36, 2, 32,-"Europe/Tallinn", 2, "toTimeZone", 2, 2, "print", 1, 35, 36, 2, 32, "Europe/Tallinn", 2, "toTimeZone", 2, 2, "toString",-1, 2, "print", 1, 35, 32, "-", 2, "print", 1, 35, 36, 2, 32, "America/New_York", 2, "toTimeZone", 2, 2, "print", 1, 35,-36, 2, 32, "America/New_York", 2, "toTimeZone", 2, 2, "toString", 1, 2, "print", 1, 35, 32, "------", 2, "print", 1, 35,-34, 1234334543.123, 2, "fromUnixTimestamp", 1, 32, "timestamp: ", 36, 3, 2, "print", 2,-35, 32, "toString(timestamp): ", 36, 3, 2, "toString", 1, 2, "print", 2, 35, 32,+"toInt", 1, 2, "print", 1, 35, 36, 1, 32, "America/New_York", 2, "toUnixTimestamp", 2, 2, "toInt", 1, 2, "print", 1, 35,+32, "-", 2, "print", 1, 35, 32, "2024-05-03T12:34:56Z", 2, "toDateTime", 1, 36, 2, 2, "print", 1, 35, 36, 2, 2,+"toString", 1, 2, "print", 1, 35, 36, 2, 2, "toUnixTimestamp", 1, 2, "toInt", 1, 2, "print", 1, 35, 32, "------", 2,+"print", 1, 35, 36, 2, 32, "Europe/Brussels", 2, "toTimeZone", 2, 2, "print", 1, 35, 36, 2, 32, "Europe/Brussels", 2,+"toTimeZone", 2, 2, "toString", 1, 2, "print", 1, 35, 32, "-", 2, "print", 1, 35, 36, 2, 32, "Europe/Tallinn", 2,+"toTimeZone", 2, 2, "print", 1, 35, 36, 2, 32, "Europe/Tallinn", 2, "toTimeZone", 2, 2, "toString", 1, 2, "print", 1,+35, 32, "-", 2, "print", 1, 35, 36, 2, 32, "America/New_York", 2, "toTimeZone", 2, 2, "print", 1, 35, 36, 2, 32,+"America/New_York", 2, "toTimeZone", 2, 2, "toString", 1, 2, "print", 1, 35, 32, "------", 2, "print", 1, 35, 34,+1234334543.123, 2, "fromUnixTimestamp", 1, 32, "timestamp: ", 36, 3, 2, "print", 2, 35,+32, "toString(timestamp): ", 36, 3, 2, "toString", 1, 2, "print", 2, 35, 32,"toInt(timestamp): ", 36, 3, 2, "toInt", 1, 2, "print", 2, 35, 32,"toDateTime(toInt(timestamp)): ", 36, 3, 2, "toInt", 1, 2, "toDateTime", 1, 2, "print", 2, 35, 32,"toInt(toDateTime(toInt(timestamp))): ", 36, 3, 2, "toInt", 1, 2, "toDateTime", 1, 2, "toInt", 1, 2, "print", 2,diff --git a/common/hogvm/__tests__/__snapshots__/date.js b/common/hogvm/__tests__/__snapshots__/date.jsindex dca27310c804..af84721f2395 100644--- a/common/hogvm/__tests__/__snapshots__/date.js+++ b/common/hogvm/__tests__/__snapshots__/date.js@@ -131,6 +131,7 @@ let dt2 = toDate("2024-05-03");print(dt2);print(toString(dt2));print(toInt(toUnixTimestamp(dt2)));+print(toInt(toUnixTimestamp(dt2, "America/New_York")));print("-");let dt3 = toDateTime("2024-05-03T12:34:56Z");print(dt3);diff --git a/common/hogvm/__tests__/__snapshots__/date.stdout b/common/hogvm/__tests__/__snapshots__/date.stdoutindex 12987d3fefcd..44e5ddab6f0f 100644--- a/common/hogvm/__tests__/__snapshots__/date.stdout+++ b/common/hogvm/__tests__/__snapshots__/date.stdout@@ -5,6 +5,7 @@ DateTime(1234334543.0, 'UTC')Date(2024, 5, 3)2024-05-031714694400+1714694400-DateTime(1714739696.0, 'UTC')2024-05-03T12:34:56.000Zdiff --git a/common/hogvm/__tests__/date.hog b/common/hogvm/__tests__/date.hogindex 2e0df7c712b8..5e8c870c0a8b 100644--- a/common/hogvm/__tests__/date.hog+++ b/common/hogvm/__tests__/date.hog@@ -8,6 +8,7 @@ let dt2 := toDate('2024-05-03')print(dt2)print(toString(dt2))print(toInt(toUnixTimestamp(dt2)))+print(toInt(toUnixTimestamp(dt2, 'America/New_York')))print('-')let dt3 := toDateTime('2024-05-03T12:34:56Z')diff --git a/common/hogvm/python/stl/date.py b/common/hogvm/python/stl/date.pyindex 0724414d1dc7..5ca8ad80772d 100644--- a/common/hogvm/python/stl/date.py+++ b/common/hogvm/python/stl/date.py@@ -18,8 +18,9 @@ def to_hog_date(year: int, month: int, day: int):def to_hog_datetime(timestamp: int | float | dict, zone: Optional[str] = None):if isinstance(timestamp, dict) and is_hog_date(timestamp):- dt = datetime.datetime(- year=timestamp["year"], month=timestamp["month"], day=timestamp["day"], tzinfo=pytz.timezone(zone or "UTC")+ # `localize`, never `tzinfo=`, for the reason given at the end of `_parse_date_like`.+ dt = pytz.timezone(zone or "UTC").localize(+ datetime.datetime(year=timestamp["year"], month=timestamp["month"], day=timestamp["day"]), is_dst=True)return {"__hogDateTime__": True,@@ -44,9 +45,8 @@ def toUnixTimestamp(date, timezone: Optional[str] = None):if isinstance(date, dict) and is_hog_datetime(date):return date["dt"]if isinstance(date, dict) and is_hog_date(date):- return datetime.datetime(- year=date["year"], month=date["month"], day=date["day"], tzinfo=pytz.timezone(timezone or "UTC")- ).timestamp()+ # A Date is UTC midnight and ignores `timezone`, as in the TypeScript and Rust VMs.+ return to_hog_datetime(date)["dt"]# A naive string is anchored to `timezone` (UTC when unset), matching Rust's# `naive_to_seconds(s, zone)` and TypeScript's `fromISO(input, {zone})`. It used to be parsed