No idea what it is doing... very sad
This commit is contained in:
@@ -4,7 +4,7 @@ import { useSettings } from '../../hooks/useSettings';
|
||||
import { Pagination } from './Pagination';
|
||||
import { Edit2, Check, X, Trash2 } from 'lucide-react';
|
||||
import type { SleepSessionRead } from '../../types';
|
||||
import { formatDateTime, toLocalDatetimeInputValue, getDurationMinutes, formatMinutes, toUTCFromLocalInput } from '../../utils/time';
|
||||
import { formatDateTime, toLocalDatetimeInputValue, getDurationMinutes, formatMinutes, toUTCFromLocalInput, parseBackendDateTime } from '../../utils/time';
|
||||
|
||||
export function SessionList() {
|
||||
const { sessions, isLoading, updateSession, deleteSession, isDeleting } = useSessions();
|
||||
@@ -57,8 +57,8 @@ export function SessionList() {
|
||||
|
||||
const startEditing = (s: SleepSessionRead) => {
|
||||
setEditingId(s.id);
|
||||
setEditStart(toLocalDatetimeInputValue(new Date(s.start_time)));
|
||||
setEditEnd(s.end_time ? toLocalDatetimeInputValue(new Date(s.end_time)) : '');
|
||||
setEditStart(toLocalDatetimeInputValue(parseBackendDateTime(s.start_time)));
|
||||
setEditEnd(s.end_time ? toLocalDatetimeInputValue(parseBackendDateTime(s.end_time)) : '');
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
@@ -161,6 +161,6 @@ export function SessionList() {
|
||||
onPageChange={setCurrentPage}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div >
|
||||
);
|
||||
}
|
||||
|
||||
@@ -198,3 +198,15 @@ export function formatMinutes(totalMinutes: number): string {
|
||||
}
|
||||
return `${mins}m`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a backend timestamp string into a Date object,
|
||||
* ensuring it is treated as UTC if no timezone info is present.
|
||||
*/
|
||||
export function parseBackendDateTime(time: string): Date {
|
||||
if (typeof time === 'string' && !time.endsWith('Z') && !time.includes('+')) {
|
||||
return new Date(time + 'Z');
|
||||
}
|
||||
// If it already has Z or offset, new Date() will handle it correctly.
|
||||
return new Date(time);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user