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

Aperta Adatta ai principianti
#360 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Inizia da packages/cel/src/std/cast.ts, in corrispondenza della registrazione di timestamp(int), e confrontala con il controllo dell’intervallo esistente createTimestamp(x, 0). Esegui i casi di conformità del timestamp timestamp_range/from_int_under e from_int_over, quindi verifica che i secondi vengano convertiti correttamente e che i valori fuori intervallo vengano rifiutati. L’issue non indica il file di test locale, quindi individua dove vengono eseguiti questi casi di conformità.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

timestamp(int) interprets the integer as milliseconds since the Unix epoch. cel-go and cel-java (int64_to_timestamp) and the conformance tests timestamp_range/from_int_under and from_int_over treat it as seconds, and int(timestamp) in cel-es itself returns seconds, so int(timestamp(x)) does not round trip. Out-of-range values are also not rejected.

Steps to Reproduce

import { run } from "@bufbuild/cel";

for (const e of [
  "string(timestamp(1700000000))",
  "int(timestamp(1700000000))",
  'timestamp(1) == timestamp("1970-01-01T00:00:01Z")',
  "string(timestamp(-62135596801))",
]) {
  try {
    console.log(e, "=>", run(e, {}));
  } catch (x) {
    console.log(e, "THROWS", x.message);
  }
}

node ts.mjs

Expected Behavior

string(timestamp(1700000000)) => 2023-11-14T22:13:20Z
int(timestamp(1700000000)) => 1700000000n
timestamp(1) == timestamp("1970-01-01T00:00:01Z") => true
string(timestamp(-62135596801)) => (error: timestamp out of range)

Actual Behavior

string(timestamp(1700000000)) => 1970-01-20T16:13:20Z
int(timestamp(1700000000)) => 1700000n
timestamp(1) == timestamp("1970-01-01T00:00:01Z") => false
string(timestamp(-62135596801)) => 1968-01-12T20:06:43.199Z

Screenshots/Logs

See above.

Environment

  • @bufbuild/cel version: 0.6.2 (also main at 34f0bee)
  • @bufbuild/cel-spec version: not used
  • Node.js version: v26.13.0

Possible Solution

packages/cel/src/std/cast.ts:122 registers timestamp(int) as timestampFromMs(Number(x)); building it from seconds with the existing range check (as createTimestamp(x, 0) does) would match the other implementations.

Additional Context

Conformance cases: https://github.com/google/cel-spec/blob/master/tests/simple/testdata/timestamps.textproto

Credit: https://ucsbplse.github.io/

Lingua principale
TypeScript
Stelle
42
Fork
8
Merge medio
1g 12h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bufbuild/cel-es

Tutte le issue di bufbuild/cel-es

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.