Skip to content

toMillis returns incorrect timestamp with more then 3 digits in fractional seconds #778

@deity-bram

Description

@deity-bram

Using this a picture and date with a more precise format then 3 digits returns an invalid timestamp.

While not using a picture returns the correct timestamp.

$toMillis("2026-04-08T19:05:04.94756", "[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f1]")

Will return 1775675198756 (2026-04-08T19:06:38.756Z)

While it should 1775667904947 (2026-04-08T17:05:04.947Z)

This will happen if you use fractional precision. [f1], or specifying the decimals f[00001].

Code snippet

const JSONata = require("jsonata");

const inputData = "2026-04-08T19:05:04.94756";   // Change timestamp
let mapping = `$toMillis($, "[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f1]")`; // change or remove picture

(async () => {
  const expression = JSONata(mapping);
  const transformedData = await expression.evaluate(inputData);
  const dDate = new Date(transformedData);

  console.log(`input              :${inputData}`);
  console.log(`timestamp     :${transformedData}`);
  console.log(`date               :${dDate.toISOString()}`);
})();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions