Files
EnvelopeGenerator/EnvelopeGenerator.Web/wwwroot/js/util.js
TekH 8cf6484786 Dynamic locale support for date formatting functions
Replaced hardcoded 'de-DE' locale with a new getCurrentCulture function that selects the user's culture from localized.culture or navigator.language. Date formatting now adapts to user language settings in detailedCurrentDate and getLocaleDateString.
2026-02-16 17:34:49 +01:00

28 lines
1.0 KiB
JavaScript

const getCurrentCulture = () => (typeof localized !== 'undefined' && localized.culture) ? localized.culture : (navigator.language || 'en-US');
const B64ToBuff = (base64String) => new Uint8Array(Array.from(atob(base64String), char => char.charCodeAt(0))).buffer;
const getLocaleDateString = _ => new Date().toLocaleDateString(getCurrentCulture())
function detailedCurrentDate() {
return new Intl.DateTimeFormat(getCurrentCulture(), {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
timeZoneName: 'shortOffset'
}).format();
}
function findNearest(origin, getX, getY, dests) {
const distanceToOrigin = (point) => Math.sqrt((getX(origin) - getX(point))**2 + (getY(origin) - getY(point))**2);
return dests.reduce(
(nearest, dest) => {
const dist = distanceToOrigin(dest);
return dist < nearest.dist ? {dist, dest} : nearest;
},
{dist: Infinity, dest: null}
).dest;
}