Fix timezone issue in date handling - use local dates instead of UTC
This commit is contained in:
@@ -126,7 +126,20 @@
|
||||
});
|
||||
|
||||
function setDefaultDate() {
|
||||
document.getElementById('dateInput').value = new Date().toISOString().split('T')[0];
|
||||
// Use local date format YYYY-MM-DD
|
||||
const today = new Date();
|
||||
const year = today.getFullYear();
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(today.getDate()).padStart(2, '0');
|
||||
document.getElementById('dateInput').value = `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
// Helper function to format date as YYYY-MM-DD in local timezone
|
||||
function formatDateLocal(date) {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
async function loadTasks() {
|
||||
@@ -244,7 +257,7 @@
|
||||
const today = new Date();
|
||||
const day = today.getDay();
|
||||
const diff = today.getDate() - day + (day === 0 ? -6 : 1) + (offset * 7);
|
||||
const monday = new Date(today.setDate(diff));
|
||||
const monday = new Date(today.getFullYear(), today.getMonth(), diff);
|
||||
monday.setHours(0, 0, 0, 0);
|
||||
return monday;
|
||||
}
|
||||
@@ -258,8 +271,11 @@
|
||||
document.getElementById('weekLabel').textContent =
|
||||
`${weekStart.toLocaleDateString('en-AU', options)} - ${weekEnd.toLocaleDateString('en-AU', options)}, ${weekEnd.getFullYear()}`;
|
||||
|
||||
// Use local date format (YYYY-MM-DD) instead of toISOString() to avoid timezone issues
|
||||
const weekStartStr = formatDateLocal(weekStart);
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/weekly-summary?week_start=${weekStart.toISOString()}`);
|
||||
const response = await fetch(`/api/weekly-summary?week_start=${weekStartStr}`);
|
||||
const data = await response.json();
|
||||
renderWeeklySummary(data);
|
||||
} catch (error) {
|
||||
@@ -328,7 +344,9 @@
|
||||
|
||||
let html = '';
|
||||
entries.slice(0, 20).forEach(entry => {
|
||||
const date = new Date(entry.date);
|
||||
// Parse date as local date (add T00:00:00 to treat as local, not UTC)
|
||||
const dateParts = entry.date.split('-');
|
||||
const date = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);
|
||||
const dateStr = date.toLocaleDateString('en-AU', { weekday: 'short', month: 'short', day: 'numeric' });
|
||||
|
||||
html += `<div class="entry-item" data-id="${entry.id}">
|
||||
@@ -371,8 +389,8 @@
|
||||
|
||||
const data = window.currentWeekData;
|
||||
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
|
||||
const weekStart = new Date(data.week_start);
|
||||
const weekEnd = new Date(data.week_end);
|
||||
const weekStart = new Date(data.week_start + 'T00:00:00');
|
||||
const weekEnd = new Date(data.week_end + 'T00:00:00');
|
||||
const options = { year: 'numeric', month: 'long', day: 'numeric' };
|
||||
|
||||
document.getElementById('printPeriod').textContent =
|
||||
|
||||
Reference in New Issue
Block a user