Added Utils.js, for miscellaneous Javascript functions

This commit is contained in:
Sander Ferdinand 2018-04-21 22:22:13 +02:00
parent 7fe9d71eb3
commit 75ccc7a31b
2 changed files with 27 additions and 0 deletions

25
js/Utils.js Normal file
View file

@ -0,0 +1,25 @@
/**
* Formats a date.
* @param {date} date - toggle decorations
* @param {params} params -
*/
function formatDate( date, params ) {
var options = {
weekday: "short",
year: "numeric",
month: "long",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
timeZone: "UTC",
timeZoneName: "short",
};
options = [options, params].reduce(function (r, o) {
Object.keys(o).forEach(function (k) { r[k] = o[k]; });
return r;
}, {});
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
return new Date( date ).toLocaleString( 'en-US', options );
}

View file

@ -206,5 +206,7 @@
<file>images/warning.png</file> <file>images/warning.png</file>
<file>images/checkedBlackIcon.png</file> <file>images/checkedBlackIcon.png</file>
<file>images/rightArrowInactive.png</file> <file>images/rightArrowInactive.png</file>
<file>js/Windows.js</file>
<file>js/Utils.js</file>
</qresource> </qresource>
</RCC> </RCC>