From 5dae8a6f663efdb59cd42dd772f228773b29415b Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 19 Jun 2025 02:52:48 +0200 Subject: Factor out locale. --- main.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'main.js') diff --git a/main.js b/main.js index a24f1c5..ef288dd 100644 --- a/main.js +++ b/main.js @@ -62,6 +62,7 @@ proj4.defs('EPSG:3006', '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 registerProjection(proj4); const PROJECTION = getProjection('EPSG:3006'); +const LOCALE = 'sv-SE'; /* Lantmäteriet uses a tile-scheme where the origin (upper-left corner) is at * N8500000 E-1200000 (SWEREF99 TM), where each tile is 256×256 pixels, and where @@ -485,6 +486,7 @@ if (window.location === window.parent.location) { }); }); + const dateFormatter = new Intl.DateTimeFormat(LOCALE); btn.onclick = function() { infoMetadataAccordions.forEach((x) => x.element.replaceChildren()); modal.show(); @@ -543,7 +545,7 @@ if (window.location === window.parent.location) { ' Lokalt skikt (vectiler) genererades ' + last_updated .sort() - .map((ts) => new Date(ts).toLocaleDateString('sv-SE')) + .map((ts) => dateFormatter.format(new Date(ts))) .join('; ') + '.' ); li.appendChild(t); @@ -638,8 +640,7 @@ if (window.location === window.parent.location) { } const t1 = document.createTextNode(' ändrades senast '); p.appendChild(t1); - const d = new Date(x.last_modified); - const td = document.createTextNode(d.toLocaleDateString('sv-SE')); + const td = document.createTextNode(dateFormatter.format(new Date(x.last_modified))); p.appendChild(td); const t2 = document.createTextNode('.'); p.appendChild(t2); @@ -4545,6 +4546,7 @@ const disposePopover = (function() { }; /* format value to HTML */ + const formatNumberLocale = new Intl.NumberFormat(LOCALE); const formatValue = function(value, options) { let unit = options?.unit; if (options?.fn == null) { @@ -4584,7 +4586,7 @@ const disposePopover = (function() { return document.createTextNode(value); case 'number': if (unit != null) { - return document.createTextNode(value.toLocaleString('sv-SE') + '\u202F' + unit); + return document.createTextNode(formatNumberLocale.format(value) + '\u202F' + unit); } return document.createTextNode(value.toString()); default: -- cgit v1.2.3