You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PackageHelper/www/assets/js/util.js

41 lines
1.3 KiB
JavaScript

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/**
* Generate a UUID.
* From https://stackoverflow.com/a/2117523
* @returns {String}
*/
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
function timestampToDateTimeString(timestamp) {
var date = new Date(timestamp * 1000);
var pm = date.getHours() >= 12;
var hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours();
hours = (hours == 0 ? 12 : hours);
var minutes = date.getMinutes();
var time = hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + " " + (pm ? "PM" : "AM");
return date.toLocaleDateString() + " " + time;
}
function timestampToTimeString(timestamp) {
var date = new Date(timestamp * 1000);
var pm = date.getHours() >= 12;
var hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours();
hours = (hours == 0 ? 12 : hours);
var minutes = date.getMinutes();
var time = hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + " " + (pm ? "PM" : "AM");
return time;
}