fix: update date handling to remove timezone offset for hunts
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 29s
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 29s
This commit is contained in:
@@ -224,12 +224,12 @@ const Hunts = {
|
||||
|
||||
isHidden(hunt) {
|
||||
if (!hunt.hidden_until_start || !hunt.start_date) return false;
|
||||
return new Date(hunt.start_date + 'Z') > new Date();
|
||||
return new Date(hunt.start_date) > new Date();
|
||||
},
|
||||
|
||||
hasStarted(hunt) {
|
||||
if (!hunt.start_date) return true;
|
||||
return new Date(hunt.start_date + 'Z') <= new Date();
|
||||
return new Date(hunt.start_date) <= new Date();
|
||||
},
|
||||
|
||||
resetScans(id) {
|
||||
|
||||
@@ -57,4 +57,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Convert datetime-local (user's local time) to UTC ISO before submit
|
||||
document.querySelector('form').addEventListener('submit', function() {
|
||||
['start_date', 'expiry_date'].forEach(function(name) {
|
||||
var input = document.getElementById(name);
|
||||
if (input && input.value) {
|
||||
var d = new Date(input.value);
|
||||
if (!isNaN(d)) input.value = d.toISOString();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<%- include('../partials/footer') %>
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
</span>
|
||||
</div>
|
||||
<div style="display: flex; gap: 0.4rem; align-items: center;">
|
||||
<% if (hunt.hidden_until_start && hunt.start_date && new Date(hunt.start_date + 'Z') > new Date()) { %>
|
||||
<% if (hunt.hidden_until_start && hunt.start_date && new Date(hunt.start_date) > new Date()) { %>
|
||||
<span class="badge expired" style="font-size: 0.7rem;">Hidden</span>
|
||||
<% } else if (hunt.start_date && new Date(hunt.start_date + 'Z') > new Date()) { %>
|
||||
<% } else if (hunt.start_date && new Date(hunt.start_date) > new Date()) { %>
|
||||
<span class="badge" style="font-size: 0.7rem;">Upcoming</span>
|
||||
<% } %>
|
||||
<span class="badge">Manage</span>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<div class="form-group">
|
||||
<label for="start_date">Start Date (optional)</label>
|
||||
<input type="datetime-local" id="start_date" name="start_date" class="form-control"
|
||||
value="<%= hunt.start_date ? new Date(hunt.start_date).toISOString().slice(0, 16) : '' %>">
|
||||
data-utc="<%= hunt.start_date || '' %>">
|
||||
<div class="form-hint">When the hunt becomes active. Leave blank to start immediately.</div>
|
||||
</div>
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<div class="form-group">
|
||||
<label for="expiry_date">Expiry Date (optional)</label>
|
||||
<input type="datetime-local" id="expiry_date" name="expiry_date" class="form-control"
|
||||
value="<%= hunt.expiry_date ? new Date(hunt.expiry_date).toISOString().slice(0, 16) : '' %>">
|
||||
data-utc="<%= hunt.expiry_date || '' %>">
|
||||
<div class="form-hint">Leave blank for no expiry.</div>
|
||||
</div>
|
||||
|
||||
@@ -53,6 +53,30 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Populate datetime-local inputs from stored UTC values (convert to local)
|
||||
document.querySelectorAll('input[data-utc]').forEach(function(input) {
|
||||
var utc = input.dataset.utc;
|
||||
if (utc) {
|
||||
var d = new Date(utc);
|
||||
if (!isNaN(d)) {
|
||||
var local = new Date(d.getTime() - d.getTimezoneOffset() * 60000);
|
||||
input.value = local.toISOString().slice(0, 16);
|
||||
}
|
||||
}
|
||||
});
|
||||
// Convert datetime-local (user's local time) to UTC ISO before submit
|
||||
document.querySelector('form').addEventListener('submit', function() {
|
||||
['start_date', 'expiry_date'].forEach(function(name) {
|
||||
var input = document.getElementById(name);
|
||||
if (input && input.value) {
|
||||
var d = new Date(input.value);
|
||||
if (!isNaN(d)) input.value = d.toISOString();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="card" style="border: 2px solid var(--danger); margin-top: 1.5rem;">
|
||||
<div class="card-header" style="color: var(--danger);">Danger Zone</div>
|
||||
|
||||
|
||||
@@ -56,9 +56,9 @@
|
||||
<% if (hunt.expiry_date) { %> · Expires <time datetime="<%= hunt.expiry_date %>"><%= new Date(hunt.expiry_date).toLocaleDateString() %></time><% } %>
|
||||
</span>
|
||||
</div>
|
||||
<% if (hunt.expiry_date && new Date(hunt.expiry_date + 'Z') < new Date()) { %>
|
||||
<% if (hunt.expiry_date && new Date(hunt.expiry_date) < new Date()) { %>
|
||||
<span class="badge expired">Expired</span>
|
||||
<% } else if (hunt.start_date && new Date(hunt.start_date + 'Z') > new Date()) { %>
|
||||
<% } else if (hunt.start_date && new Date(hunt.start_date) > new Date()) { %>
|
||||
<span class="badge">Upcoming</span>
|
||||
<% } else { %>
|
||||
<span class="badge"><%= hunt.package_count %> packages</span>
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
<% if (hunt.expiry_date) { %>
|
||||
· Expires <time datetime="<%= hunt.expiry_date %>"><%= new Date(hunt.expiry_date).toLocaleDateString() %></time>
|
||||
<% } %>
|
||||
<% if (hunt.start_date && new Date(hunt.start_date + 'Z') > new Date()) { %>
|
||||
<% if (hunt.start_date && new Date(hunt.start_date) > new Date()) { %>
|
||||
· Starts <time datetime="<%= hunt.start_date %>"><%= new Date(hunt.start_date).toLocaleDateString() %></time>
|
||||
<% } %>
|
||||
</span>
|
||||
</div>
|
||||
<% if (hunt.expiry_date && new Date(hunt.expiry_date + 'Z') < new Date()) { %>
|
||||
<% if (hunt.expiry_date && new Date(hunt.expiry_date) < new Date()) { %>
|
||||
<span class="badge expired">Expired</span>
|
||||
<% } else if (hunt.start_date && new Date(hunt.start_date + 'Z') > new Date()) { %>
|
||||
<% } else if (hunt.start_date && new Date(hunt.start_date) > new Date()) { %>
|
||||
<span class="badge">Upcoming</span>
|
||||
<% } else { %>
|
||||
<span class="badge"><%= hunt.package_count %> packages</span>
|
||||
|
||||
Reference in New Issue
Block a user