Skip to content

Commit

Permalink
Store Datetimes as UTC. Use Luxon for formatting datetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
svera authored Jan 12, 2025
1 parent 67d474c commit 3bed823
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/webserver/controller/auth/signin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (a *Controller) SignIn(c *fiber.Ctx) error {
}, "layout")
}

user.LastLogin = time.Now()
user.LastLogin = time.Now().UTC()
if err := a.repository.Update(user); err != nil {
log.Printf("error updating user last login time: %v\n", err)
return fiber.ErrInternalServerError
Expand Down
4 changes: 4 additions & 0 deletions internal/webserver/embedded/css/display.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ a.collapse-control.collapsed:after {
.actions .dropdown-menu {
white-space: nowrap;
}

.datetime::first-letter {
text-transform: capitalize;
}
11 changes: 11 additions & 0 deletions internal/webserver/embedded/js/datetime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

import { DateTime } from "./luxon.min.js";

document.addEventListener('DOMContentLoaded', function() {
const datetime = document.querySelectorAll('.datetime span');
datetime.forEach(function(element) {
const dt = DateTime.fromISO(element.textContent);
element.textContent = dt.toRelative({ locale: document.documentElement.lang });
});
});
1 change: 1 addition & 0 deletions internal/webserver/embedded/js/luxon.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/webserver/embedded/translations/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@
"Titles by %s": "Títulos de %s"
"Send to %s": "Enviar a %s"
"Home": "Inicio"
"Last login": "Último Acceso"
"Last login": "Último acceso"
"Never": "Nunca"
5 changes: 3 additions & 2 deletions internal/webserver/embedded/views/user/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ <h2>{{t $lang "Users"}}</h2>
<span class="badge rounded-pill text-bg-secondary">Admin</span>
{{end}}
</td>
<td>
<td class="datetime">
{{if $user.LastLogin.IsZero }}
{{t $lang "Never"}}
{{else}}
{{$user.LastLogin.Format "2006-01-02 15:04"}}
<span>{{$user.LastLogin.Format "2006-01-02T15:04:05Z"}}</span>
{{end}}
</td>
<td class="text-end">
Expand All @@ -55,3 +55,4 @@ <h2>{{t $lang "Users"}}</h2>
{{template "partials/delete-modal" dict "Lang" $lang "Action" "users" "ModalHeader" "Delete user" "ModalBody" "Are you sure you want to delete this user?" "ModalErrorMessage" "There was an error deleting the user, try again later"}}

<script type="text/javascript" src="/js/delete.js"></script>
<script type="module" src="/js/datetime.js"></script>

0 comments on commit 3bed823

Please sign in to comment.