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

Abierto Apto para principiantes
#360 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

Empieza en packages/cel/src/std/cast.ts, en el registro de timestamp(int), y compáralo con la comprobación de rango existente createTimestamp(x, 0). Ejecuta los casos de conformidad de timestamp timestamp_range/from_int_under y from_int_over; después, verifica que los segundos se conviertan correctamente y que se rechacen los valores fuera de rango. El issue no indica el archivo de pruebas local, así que localiza dónde se ejecutan esos casos de conformidad.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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/

Lenguaje dominante
TypeScript
Estrellas
42
Forks
8
Merge medio
1 d 12 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bufbuild/cel-es

Todos los issues de bufbuild/cel-es

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.