Skip to content

Commit 38877bb

Browse files
authored
Merge pull request #855 from CodeWithCJ/dev
date shift issue fix
2 parents 94f12a1 + 92dc47a commit 38877bb

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

SparkyFitnessFrontend/src/contexts/PreferencesContext.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ export const PreferencesProvider: React.FC<{ children: React.ReactNode }> = ({
345345

346346
if (typeof date === 'string') {
347347
// If it's a full ISO string with time (e.g. 2026-02-16T...), keep it as is for parseISO
348-
if (date.match(/^\d{4}-\d{2}-\d{2}$/) || date.includes('T00:00:00')) {
348+
if (
349+
date.match(/^\d{4}-\d{2}-\d{2}$/) ||
350+
date.includes('T00:00:00') ||
351+
(date.endsWith('Z') && date.includes('T00:00'))
352+
) {
349353
// IMPORTANT: Treat YYYY-MM-DD as a literal local date to avoid UTC-to-Local shifting.
350354
const datePart = date.split('T')[0];
351355
if (datePart) {
@@ -389,6 +393,22 @@ export const PreferencesProvider: React.FC<{ children: React.ReactNode }> = ({
389393
loggingLevel,
390394
`PreferencesProvider: Parsing date string "${dateString}".`
391395
);
396+
397+
// Handle literal date strings (YYYY-MM-DD or DB DATE format) to prevent shifting
398+
if (
399+
dateString.match(/^\d{4}-\d{2}-\d{2}$/) ||
400+
dateString.includes('T00:00:00') ||
401+
(dateString.endsWith('Z') && dateString.includes('T00:00'))
402+
) {
403+
const datePart = dateString.split('T')[0];
404+
if (datePart) {
405+
const [year, month, day] = datePart.split('-').map(Number);
406+
if (year && month && day) {
407+
return new Date(year, month - 1, day);
408+
}
409+
}
410+
}
411+
392412
const parsedDate = parseISO(dateString);
393413
return startOfDay(parsedDate);
394414
},

0 commit comments

Comments
 (0)