[openstreetmap/openstreetmap-website] Localise message timestamps (Issue #4067)
Dimitar
notifications at github.com
Fri Jun 16 17:55:34 UTC 2023
We don't need to know the user's timezone, it can be processed by the browser. If the date is supplied as Unix timestamp (`<time datetime="unix_timestamp_in_UTC">fallback</time>`), then we can have some JS code to convert into the local time
```js
document.onload(()=>{
var time_els = document..querySelectorAll("time");
for (i = 0; i < time_els.length; i++) {
time_els.innerText = new Date(new Date(time_els.getAttribute("datetime") * 1000) + "UTC").toLocaleString("xx");
}
});
```
The fallback is optional, it is needed for ancient browsers and browsers that don't support Javascript.
`xx` is the locale, it can be "en" or "en-us", regardless it will produce correct results.
`toLocaleString` seems to be supported by all major browsers (see https://caniuse.com/mdn-javascript_builtins_date_tolocalestring).
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/4067#issuecomment-1595048926
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/issues/4067/1595048926 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20230616/69661609/attachment.htm>
More information about the rails-dev
mailing list