Use Intl instead of Moment.js

Hi,I’ve been using a Client-side Event that calculates hours between two dates and time. In this script I’ve used moment.js to calculate and format the date/time. From 2022 PHPMaker don’t use moment.js anymore so I want to change. But I misses functions to do the calculations.Any ideas how to do it in a nice way?This is my old ugly script:

{ // keys = event types, values = handler functions mamam
    "change keyup": function(e) {
        var $row = $(this).fields();
        var earlierDateTime = $row["startdate"].val()+$row["starttime"].val();
        var laterDateTime = $row["enddate"].val()+$row["endtime"].val();

        console.log("Start: "+earlierDateTime);
        console.log("Stop: "+laterDateTime);


        const ms = moment(laterDateTime, "YYYY-MM-DD hh:mm:ss").diff(moment(earlierDateTime, "YYYY-MM-DD hh:mm:ss"));
        const d = moment.duration(ms);
        const diff = `${Math.floor(d.asHours())}${moment.utc(ms).format(":mm:ss")}`;
        console.log(("0" + diff).slice(-2));

        var hoursMinutes = diff.split(/[.:]/);
        console.log("hoursMinutes: "+hoursMinutes);
        var hours = parseInt(hoursMinutes[0], 10);
        console.log("hours: "+hours);
        var minutes = hoursMinutes[1] ? parseInt(hoursMinutes[1], 10) : 0;
        console.log("minutes: "+minutes);
        var result = hours + minutes / 60;
        result = result.toFixed(2).toString().replace(".", ",")

        console.log("result: "+result);

        $row["debtime"].value(result);
        console.log("Tid: "+result);
    }
}

I’v also tried to use Composer and npm package to include moment.js but I get error: Uncaught ReferenceError: moment is not defined…

riverman wrote:

Uncaught ReferenceError: moment is not defined…

Make sure you have already included the related .js and .css files.

Read Migrating to v2022 → Internationalization (i18n) → Point 4.