diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2025-06-19 02:52:48 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2025-06-19 14:45:14 +0200 |
commit | 5dae8a6f663efdb59cd42dd772f228773b29415b (patch) | |
tree | e8c6aeb5526d41384895c9ff4dd017f57f1191a7 /main.js | |
parent | 5c377a1eb64f7804358f6610624ff15097fb83c2 (diff) |
Factor out locale.
Diffstat (limited to 'main.js')
-rw-r--r-- | main.js | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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: |