Cloudflare Pages Functions : bug same code different results between local and deployed

const getRandomISODateNearLastHour = function () {
    let dt = new Date();
    let timesamp = dt.getTime();
    timesamp -= 3600 * 1000;
    let dt2 = new Date(timesamp);
    dt2.setMinutes(Math.random() * 60, Math.random() * 60, Math.random() * 100);
    return dt2.toISOString();

This code return 1969-12-31T23:14:21.049Z at Cloudflare Pages and 2022-03-05T08:50:20.097Z at local (with obvious small difference due to random) with Wrangler2 0.16
It seems that Cloudflare Pages Functions return 01/01/1970 to new Date()
but it must returns the current date cf: MDN
NodeJS is set at the same version with environment variable.

This is expected behavior I believe.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.