From 75ccc7a31b0ab3b969da9a599e8244a8119aa74d Mon Sep 17 00:00:00 2001 From: Sander Ferdinand Date: Sat, 21 Apr 2018 22:22:13 +0200 Subject: [PATCH] Added Utils.js, for miscellaneous Javascript functions --- js/Utils.js | 25 +++++++++++++++++++++++++ qml.qrc | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 js/Utils.js diff --git a/js/Utils.js b/js/Utils.js new file mode 100644 index 00000000..7cf582b2 --- /dev/null +++ b/js/Utils.js @@ -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 ); +} diff --git a/qml.qrc b/qml.qrc index 42b868e6..4e605d89 100644 --- a/qml.qrc +++ b/qml.qrc @@ -206,5 +206,7 @@ images/warning.png images/checkedBlackIcon.png images/rightArrowInactive.png + js/Windows.js + js/Utils.js