last updated shows in local time

This commit is contained in:
mithereal 2022-09-17 15:13:40 -07:00
parent ad2da6cdc6
commit dfad1393b2

View File

@ -35,7 +35,7 @@
<div id="child-div">
<h1>Farside [<a href="https://sr.ht/~benbusby/farside">SourceHut</a>, <a href="https://github.com/benbusby/farside">GitHub</a>]</h1>
<hr>
<h3>Last synced <%= DateTime.truncate(last_updated, :second) %> UTC</h2>
<h3>Last synced <span id="last_updated"><%= DateTime.truncate(last_updated, :second) %></span></h2>
<div>
<ul>
<%= for service <- services do %>
@ -50,4 +50,25 @@
</div>
</div>
</div>
<script>
var client_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
var options = {
timeZone: client_timezone,
year: 'numeric', month: 'numeric', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric'
};
var formatter = new Intl.DateTimeFormat([], options);
var time = "<%= DateTime.truncate(last_updated, :second) %>";
var element_to_write = document.getElementById("last_updated");
var localized_time = formatter.format(new Date(time));
element_to_write.innerHTML = localized_time;
</script>
</body>