Files
SDSStundenerfassung/public/js/format-hours.js

20 lines
661 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Gleiche Logik wie helpers/utils.js formatHoursMin für Browser (Dashboard, EJS-Seiten).
// Wird global als window.formatHoursMin bereitgestellt.
(function () {
function formatHoursMin(decimalHours) {
if (decimalHours == null || !Number.isFinite(Number(decimalHours))) return '0h 0min';
var n = Number(decimalHours);
var sign = n < 0 ? -1 : 1;
var absVal = Math.abs(n);
var h = Math.floor(absVal);
var min = Math.round((absVal - h) * 60);
if (min >= 60) {
h += 1;
min = 0;
}
var prefix = sign < 0 ? '-' : '';
return prefix + h + 'h ' + min + 'min';
}
window.formatHoursMin = formatHoursMin;
})();