Let maps consider the timezone of the application

This commit is contained in:
Eugene Burmakin 2024-05-25 20:23:33 +02:00
parent d52b538398
commit 036b21b5a5
2 changed files with 4 additions and 9 deletions

View file

@ -96,15 +96,9 @@ export default class extends Controller {
formatDate(timestamp) {
let date = new Date(timestamp * 1000); // Multiply by 1000 because JavaScript works with milliseconds
// Extracting date components
let year = date.getFullYear();
let month = ('0' + (date.getMonth() + 1)).slice(-2); // Adding 1 because getMonth() returns zero-based month
let day = ('0' + date.getDate()).slice(-2);
let hours = ('0' + date.getHours()).slice(-2);
let minutes = ('0' + date.getMinutes()).slice(-2);
let seconds = ('0' + date.getSeconds()).slice(-2);
let timezone = this.element.dataset.timezone;
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
return date.toLocaleString('en-GB', { timeZone: timezone });
}
addTileLayer(map) {

View file

@ -26,7 +26,8 @@
class="w-full"
data-controller="maps"
data-coordinates="<%= @coordinates %>"
data-center="<%= MAP_CENTER %>">
data-center="<%= MAP_CENTER %>"
data-timezone="<%= Rails.configuration.time_zone %>">
<div data-maps-target="container" class="h-[25rem] w-auto min-h-screen"></div>
</div>
</div>