Skip to content

Commit

Permalink
Drop moment.js dependency
Browse files Browse the repository at this point in the history
Addresses CVE-2022-24785
  • Loading branch information
justin-stephenson committed May 19, 2022
1 parent 88a167a commit 6f5ec24
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"date-fns": "2.25.0",
"ini": "^1.3.5",
"jquery": "3.5.1",
"moment": "2.27.0",
"raw-loader": "^0.5.1",
"react": "16.13.1",
"react-dom": "16.13.1",
Expand Down
17 changes: 15 additions & 2 deletions src/player.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import { journal } from 'journal';

const cockpit = require("cockpit");
const _ = cockpit.gettext;
const moment = require("moment");
const $ = require("jquery");

const padInt = function (n, w) {
Expand All @@ -72,8 +71,22 @@ const padInt = function (n, w) {
return ((i < 0) ? '-' : '') + s;
};

/*
* Format date and time for a number of milliseconds since Epoch.
* YYYY-MM-DD HH:mm:ss
*/
const formatDateTime = function (ms) {
return moment(ms).format("YYYY-MM-DD HH:mm:ss");
/* Convert local timezone offset */
let t = new Date(ms);
let z = t.getTimezoneOffset() * 60 * 1000;
let tLocal = t - z;
tLocal = new Date(tLocal);
let iso = tLocal.toISOString();

/* cleanup ISO format */
iso = iso.slice(0, 19);
iso = iso.replace('T', ' ');
return iso;
};

/*
Expand Down
26 changes: 22 additions & 4 deletions src/recordings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import { journal } from 'journal';
const $ = require("jquery");
const cockpit = require("cockpit");
const _ = cockpit.gettext;
const moment = require("moment");
const Player = require("./player.jsx");
const Config = require("./config.jsx");

Expand All @@ -85,14 +84,33 @@ const padInt = function (n, w) {

/*
* Format date and time for a number of milliseconds since Epoch.
* YYYY-MM-DD HH:mm:ss
*/
const formatDateTime = function (ms) {
return moment(ms).format("YYYY-MM-DD HH:mm:ss");
/* Convert local timezone offset */
let t = new Date(ms);
let z = t.getTimezoneOffset() * 60 * 1000;
let tLocal = t - z;
tLocal = new Date(tLocal);
let iso = tLocal.toISOString();

/* cleanup ISO format */
iso = iso.slice(0, 19);
iso = iso.replace('T', ' ');
return iso;
};

const formatUTC = function(date) {
return moment(date).utc()
.format("YYYY-MM-DD HH:mm:ss") + " UTC";
let iso = null;
try {
iso = new Date(date).toISOString();
iso = iso.slice(0, 19);
iso = iso.replace('T', ' ') + " UTC";
} catch (error) {
iso = "";
}

return iso;
};

/*
Expand Down

0 comments on commit 6f5ec24

Please sign in to comment.