Skip to content

Commit

Permalink
Let maps consider the timezone of the application
Browse files Browse the repository at this point in the history
  • Loading branch information
Freika committed May 25, 2024
1 parent d52b538 commit 036b21b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
12 changes: 3 additions & 9 deletions app/javascript/controllers/maps_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
let timezone = this.element.dataset.timezone;

return date.toLocaleString('en-GB', { timeZone: timezone });
}

addTileLayer(map) {
Expand Down
3 changes: 2 additions & 1 deletion app/views/map/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 036b21b

Please sign in to comment.