Files
codeql-action/node_modules/date-time/index.js
2020-05-13 11:13:27 +01:00

34 lines
723 B
JavaScript

'use strict';
const timeZone = require('time-zone');
module.exports = options => {
options = Object.assign({
date: new Date(),
local: true,
showTimeZone: false,
showMilliseconds: false
}, options);
let date = options.date;
if (options.local) {
// Offset the date so it will return the correct value when getting the ISO string
date = new Date(date.getTime() - (date.getTimezoneOffset() * 60000));
}
let end = '';
if (options.showTimeZone) {
end = ' UTC' + (options.local ? timeZone(date) : '');
}
if (options.showMilliseconds && date.getUTCMilliseconds() > 0) {
end = ` ${date.getUTCMilliseconds()}ms${end}`;
}
return date
.toISOString()
.replace(/T/, ' ')
.replace(/\..+/, end);
};