Skip to content

Treat timestamp(int) argument as seconds - #364

Open
bardrop wants to merge 1 commit into
bufbuild:mainfrom
bardrop-oss:fix-timestamp-from-int-seconds
Open

bardrop wants to merge 1 commit into
bufbuild:mainfrom
bardrop-oss:fix-timestamp-from-int-seconds

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown

Fixes #360.

timestamp(int) used timestampFromMs(Number(x)), so the integer was read as milliseconds. cel-go, cel-java and the cel-spec conformance tests (timestamp_range/from_int_under, from_int_over) read it as seconds, and int(timestamp) here already returns seconds.

This builds the value with createTimestamp(x) instead, the same helper the timestamp/duration arithmetic uses, so it also gets the existing range check (0001-01-01 to 9999-12-31).

expression before after
string(timestamp(1700000000)) 1970-01-20T16:13:20Z 2023-11-14T22:13:20Z
int(timestamp(1700000000)) 1700000n 1700000000n
timestamp(1) == timestamp("1970-01-01T00:00:01Z") false true
timestamp(-62135596801) 1968-01-12T20:06:43.199Z error: timestamp out of range

Tests: new packages/cel/src/std/cast.test.ts (fails on main, passes here). npm test in packages/cel passes (5393 tests), and npx turbo run build lint format license-header --filter=@bufbuild/cel is clean.

timestamp(int) built the timestamp from milliseconds, so it did not
match cel-go, cel-java and the cel-spec conformance tests, did not
round trip with int(timestamp), and did not reject values outside the
supported range. Build it from seconds with createTimestamp, which
also does the range check.

Fixes bufbuild#360
@CLAassistant

CLAassistant commented Nov 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@bardrop

bardrop commented Nov 19, 2026

Copy link
Copy Markdown
Author

Friendly ping when you have time. Is there anything you'd like changed here? (Same for #365.)

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.

[BUG] timestamp(int) treats its argument as milliseconds instead of seconds

2 participants