This commit is contained in:
2021-06-01 23:58:19 +00:00
parent 73d6c7c219
commit 2ddf8b9ddf
4 changed files with 80 additions and 7 deletions

View File

@@ -179,6 +179,25 @@ export default {
return true;
},
///////////////////////////////
// ROUNDING
// //https://medium.com/swlh/how-to-round-to-a-certain-number-of-decimal-places-in-javascript-ed74c471c1b8
roundAccurately: function(number, decimalPlaces) {
if (!number || number == 0 || number == NaN) {
return number;
}
let wasNegative = number < 0;
if (wasNegative) {
number = Match.abs(number); //make sure it's positive because rounding negative numbers is weird in JS
}
number = Number(
Math.round(number + "e" + decimalPlaces) + "e-" + decimalPlaces
);
if (wasNegative) {
number = 0 - number;
}
return number;
},
///////////////////////////////
// CLEAN TAG NAME
// Clean up a tag with same rules as server
//

View File

@@ -243,11 +243,47 @@ export default {
}
//instantiate a luxon date object from val which is assumed to be an iso string
let dt = window.$gz.DateTime.fromISO(val);
if (!dt.isValid) {
console.error("locale::addMinutes, input not valid:", {
val: val,
dt: dt
});
return val;
}
//add minutes
dt = dt.plus({ minutes: minutes });
return dt.toUTC().toString();
},
///////////////////////////////////////////////
// parse UTC ISO 8601 strings, diff, return hours
//
diffHoursFromUTC8601String(start, stop) {
if (!start || start == "" || !stop == null || stop == "") {
return 0;
}
//instantiate a luxon date object from val which is assumed to be an iso string
const startDate = window.$gz.DateTime.fromISO(start);
if (!startDate.isValid) {
console.error("locale::diffHours, start not valid:", {
start: start,
startDate: startDate
});
return 0;
}
const stopDate = window.$gz.DateTime.fromISO(stop);
if (!stopDate.isValid) {
console.error("locale::diffHours, start not valid:", {
stop: stop,
stopDate: stopDate
});
return 0;
}
return window.$gz.util.roundAccurately(
stopDate.diff(startDate, "hours").toObject().hours,
2
);
},
///////////////////////////////////////////////
// Local now timestamp converted to timeZoneName
// and output as ISO 8601
// (used to inform server of local client time)