Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d53887fcc | |||
| 673c151213 | |||
| 8b4f519e55 | |||
| f14e58d42c | |||
| a86bf2ded4 | |||
| 969b8e033f | |||
| cfc3156906 | |||
| 81eadf618a | |||
| 6847886e7a | |||
| 5d8a8b3c57 | |||
| 32d3e86d38 |
@@ -51,6 +51,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
|
--build-arg VITE_APP_VERSION=$(git describe --tags) \
|
||||||
|
--build-arg VITE_APP_GITSHA=$(git rev-parse --short HEAD) \
|
||||||
-t gitea.lan/jacobh2/babymonitor-frontend:${{ env.VERSION }} \
|
-t gitea.lan/jacobh2/babymonitor-frontend:${{ env.VERSION }} \
|
||||||
./frontend \
|
./frontend \
|
||||||
--push
|
--push
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
*.js
|
*.js
|
||||||
*.jsx
|
*.jsx
|
||||||
|
|
||||||
|
.omo/
|
||||||
|
|
||||||
### Node ###
|
### Node ###
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ Baby monitor - self-hosted web app for tracking infant sleep. Dual-stack monorep
|
|||||||
- **Frontend JS Slop**: NEVER create `.js` or `.jsx` files for the frontend. Use only TypeScript (`.ts`, `.tsx`). Write clean, type-safe code.
|
- **Frontend JS Slop**: NEVER create `.js` or `.jsx` files for the frontend. Use only TypeScript (`.ts`, `.tsx`). Write clean, type-safe code.
|
||||||
- **Assumption Error**: NEVER assume the content of ANY files. ALWAYS read the target file to confirm its structure and implementation before modifying or referencing it.
|
- **Assumption Error**: NEVER assume the content of ANY files. ALWAYS read the target file to confirm its structure and implementation before modifying or referencing it.
|
||||||
|
|
||||||
|
## MANDATORY EXECUTION PROTOCOLS (INJECTABLE)
|
||||||
|
|
||||||
|
The following protocols must be strictly adhered to upon injection:
|
||||||
|
- **Read Before Edit**: ALWAYS read the entire target file before performing any `edit` operation.
|
||||||
|
- **Post-Edit Verification**: Immediately after an edit, verify that no lines have been duplicated.
|
||||||
|
- **Stability Check**: Following any code change, run both backend and frontend services AND the full test suite to ensure system stability.
|
||||||
## COMMANDS
|
## COMMANDS
|
||||||
|
|
||||||
### Backend Development
|
### Backend Development
|
||||||
|
|||||||
@@ -9,6 +9,5 @@ class SleepSession(SQLModel, table=True):
|
|||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
id: Optional[int] = Field(default=None, primary_key=True)
|
||||||
start_time: datetime = Field(nullable=False)
|
start_time: datetime = Field(nullable=False)
|
||||||
end_time: Optional[datetime] = Field(default=None, nullable=True)
|
end_time: Optional[datetime] = Field(default=None, nullable=True)
|
||||||
notes: Optional[str] = Field(default=None)
|
|
||||||
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
||||||
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
||||||
|
|||||||
@@ -6,22 +6,17 @@ from pydantic import BaseModel
|
|||||||
class SleepSessionCreate(BaseModel):
|
class SleepSessionCreate(BaseModel):
|
||||||
start_time: datetime
|
start_time: datetime
|
||||||
|
|
||||||
|
|
||||||
class SleepSessionUpdate(BaseModel):
|
class SleepSessionUpdate(BaseModel):
|
||||||
start_time: Optional[datetime] = None
|
start_time: Optional[datetime] = None
|
||||||
end_time: Optional[datetime] = None
|
end_time: Optional[datetime] = None
|
||||||
notes: Optional[str] = None
|
|
||||||
|
|
||||||
|
|
||||||
class SleepSessionRead(BaseModel):
|
class SleepSessionRead(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
start_time: datetime
|
start_time: datetime
|
||||||
end_time: Optional[datetime]
|
end_time: Optional[datetime]
|
||||||
notes: Optional[str]
|
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
updated_at: datetime
|
updated_at: datetime
|
||||||
|
|
||||||
|
|
||||||
class SessionListResponse(BaseModel):
|
class SessionListResponse(BaseModel):
|
||||||
sessions: List[SleepSessionRead]
|
sessions: List[SleepSessionRead]
|
||||||
total: int
|
total: int
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
FROM node:22-alpine AS build
|
FROM node:22-alpine AS build
|
||||||
|
|
||||||
|
ARG VITE_APP_VERSION=unknown
|
||||||
|
ARG VITE_APP_GITSHA=unknown
|
||||||
|
ENV VITE_APP_VERSION=$VITE_APP_VERSION
|
||||||
|
ENV VITE_APP_GITSHA=$VITE_APP_GITSHA
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package files first to leverage Docker cache
|
# Copy package files first to leverage Docker cache
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"test": "DEBUG_PRINT_LIMIT=0 vitest run --reporter=dot --no-color",
|
"test": "DEBUG_PRINT_LIMIT=0 vitest run --reporter=dot --no-color",
|
||||||
"test:all": "vitest run && npx playwright test",
|
"test:all": "vitest run && npx playwright test",
|
||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
"clean": "find src -name '*.js' -o -name '*.jsx' -delete"
|
"clean": "find .. -not -path '*/node_modules/*' -not -name 'eslint.config.js' \\( -name '*.js' -o -name '*.jsx' \\) -delete"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/react-query": "^5.100.5",
|
"@tanstack/react-query": "^5.100.5",
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import TrackerPage from './components/tracker/TrackerPage';
|
|||||||
import StatsPage from './components/stats/StatsPage';
|
import StatsPage from './components/stats/StatsPage';
|
||||||
import Navbar from './components/Navbar';
|
import Navbar from './components/Navbar';
|
||||||
import Playground from './components/Playground';
|
import Playground from './components/Playground';
|
||||||
|
import Footer from './components/Footer';
|
||||||
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
@@ -17,6 +19,7 @@ function App() {
|
|||||||
<Route path="/playground" element={<Playground />} />
|
<Route path="/playground" element={<Playground />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</main>
|
</main>
|
||||||
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const Footer: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<footer className="py-4 text-center">
|
||||||
|
<p className="text-xs text-slate-500">
|
||||||
|
{__APP_VERSION__} ({__APP_GITSHA__})
|
||||||
|
</p>
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Footer;
|
||||||
@@ -100,8 +100,8 @@ const DailySummary: React.FC<DailySummaryProps> = ({ from_date, to_date, day_sta
|
|||||||
width={60}
|
width={60}
|
||||||
/>
|
/>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
formatter={(value: any, name: any) => [
|
formatter={(value: number | string | readonly (string | number)[] | undefined, name: string | number | undefined) => [
|
||||||
formatMinutes(Math.round(Number(value ?? 0) * 60)),
|
formatMinutes(Math.round(Number((Array.isArray(value) ? value[0] : value ?? 0) * 60))),
|
||||||
name === 'daySleep' ? 'Day' : 'Night',
|
name === 'daySleep' ? 'Day' : 'Night',
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useSettings } from '../../hooks/useSettings';
|
|||||||
import { Pagination } from './Pagination';
|
import { Pagination } from './Pagination';
|
||||||
import { Edit2, Check, X, Trash2 } from 'lucide-react';
|
import { Edit2, Check, X, Trash2 } from 'lucide-react';
|
||||||
import type { SleepSessionRead } from '../../types';
|
import type { SleepSessionRead } from '../../types';
|
||||||
import { formatDateTime, toLocalDatetimeInputValue, getDurationMinutes, formatMinutes } from '../../utils/time';
|
import { formatDateTime, toLocalDatetimeInputValue, getDurationMinutes, formatMinutes, toUTCFromLocalInput, parseBackendDateTime } from '../../utils/time';
|
||||||
|
|
||||||
export function SessionList() {
|
export function SessionList() {
|
||||||
const { sessions, isLoading, updateSession, deleteSession, isDeleting } = useSessions();
|
const { sessions, isLoading, updateSession, deleteSession, isDeleting } = useSessions();
|
||||||
@@ -29,13 +29,13 @@ export function SessionList() {
|
|||||||
|
|
||||||
const handleSave = async (id: number) => {
|
const handleSave = async (id: number) => {
|
||||||
try {
|
try {
|
||||||
await updateSession({
|
await updateSession({
|
||||||
sessionId: id,
|
sessionId: id,
|
||||||
payload: {
|
payload: {
|
||||||
start_time: new Date(editStart).toISOString(),
|
start_time: toUTCFromLocalInput(editStart),
|
||||||
end_time: editEnd ? new Date(editEnd).toISOString() : undefined,
|
end_time: editEnd ? toUTCFromLocalInput(editEnd) : undefined,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
setEditingId(null);
|
setEditingId(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@@ -57,8 +57,8 @@ export function SessionList() {
|
|||||||
|
|
||||||
const startEditing = (s: SleepSessionRead) => {
|
const startEditing = (s: SleepSessionRead) => {
|
||||||
setEditingId(s.id);
|
setEditingId(s.id);
|
||||||
setEditStart(toLocalDatetimeInputValue(new Date(s.start_time)));
|
setEditStart(toLocalDatetimeInputValue(parseBackendDateTime(s.start_time)));
|
||||||
setEditEnd(s.end_time ? toLocalDatetimeInputValue(new Date(s.end_time)) : '');
|
setEditEnd(s.end_time ? toLocalDatetimeInputValue(parseBackendDateTime(s.end_time)) : '');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
@@ -161,6 +161,6 @@ export function SessionList() {
|
|||||||
onPageChange={setCurrentPage}
|
onPageChange={setCurrentPage}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div >
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ const Timetable = ({ from_date, to_date, day_start, day_end }: TimetableProps) =
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (days.length > 0) {
|
if (days.length > 0) {
|
||||||
setSelectedDayIndex(days.length - 1);
|
const newIndex = days.length - 1;
|
||||||
|
setSelectedDayIndex(prev => (prev !== newIndex ? newIndex : prev));
|
||||||
}
|
}
|
||||||
}, [days]);
|
}, [days]);
|
||||||
|
|
||||||
@@ -158,7 +159,7 @@ const Timetable = ({ from_date, to_date, day_start, day_end }: TimetableProps) =
|
|||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div >
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Grid Container */}
|
{/* Grid Container */}
|
||||||
@@ -176,27 +177,27 @@ const Timetable = ({ from_date, to_date, day_start, day_end }: TimetableProps) =
|
|||||||
{visibleDays.map((day) => (
|
{visibleDays.map((day) => (
|
||||||
<div key={day} className="text-center text-[10px] font-medium text-gray-500 uppercase flex items-center justify-center h-2">
|
<div key={day} className="text-center text-[10px] font-medium text-gray-500 uppercase flex items-center justify-center h-2">
|
||||||
{getDayName(day)}
|
{getDayName(day)}
|
||||||
</div >
|
</div>
|
||||||
))}
|
))}
|
||||||
</div >
|
</div>
|
||||||
|
|
||||||
{/* Time Grid Container */}
|
{/* Time Grid Container */}
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<div
|
<div
|
||||||
className="grid"
|
className="grid"
|
||||||
style={{
|
style={{
|
||||||
gridTemplateColumns: tier === 'desktop'
|
gridTemplateColumns: tier === 'desktop'
|
||||||
? `4rem repeat(${days.length}, minmax(40px, 1fr))`
|
? `4rem repeat(${days.length}, minmax(40px, 1fr))`
|
||||||
: `4rem repeat(${visibleDays.length}, 1fr)`
|
: `4rem repeat(${visibleDays.length}, 1fr)`
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* Time Rows */}
|
{/* Time Rows */}
|
||||||
{timeSteps.map((step) => (
|
{timeSteps.map((step) => (
|
||||||
<Fragment key={step}>
|
<Fragment key={step}>
|
||||||
{/* Time Label */}
|
{/* Time Label */}
|
||||||
<div className="text-[10px] text-gray-400 flex items-center justify-end pr-2 h-2">
|
<div className="text-[10px] text-gray-400 flex items-center justify-end pr-2 h-2">
|
||||||
{step % 60 === 0 ? formatTimeLabel(step) : ''}
|
{step % 60 === 0 ? formatTimeLabel(step) : ''}
|
||||||
</div >
|
</div>
|
||||||
|
|
||||||
{/* Grid Cells */}
|
{/* Grid Cells */}
|
||||||
{visibleDays.map((day) => {
|
{visibleDays.map((day) => {
|
||||||
@@ -220,11 +221,11 @@ const Timetable = ({ from_date, to_date, day_start, day_end }: TimetableProps) =
|
|||||||
transform: 'translateY(-50%)'
|
transform: 'translateY(-50%)'
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div >
|
</div>
|
||||||
</div >
|
</div>
|
||||||
</div >
|
</div>
|
||||||
</div >
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Timetable;
|
export default Timetable;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
|
import { createContext, useState, useEffect, ReactNode } from 'react';
|
||||||
|
|
||||||
const STORAGE_KEY = 'baby-sleep-settings';
|
const STORAGE_KEY = 'baby-sleep-settings';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import { SettingsContext, Settings } from './SettingsProvider';
|
import { SettingsContext } from './SettingsProvider';
|
||||||
|
|
||||||
export function useSettings() {
|
export function useSettings() {
|
||||||
const context = useContext(SettingsContext);
|
const context = useContext(SettingsContext);
|
||||||
|
|||||||
@@ -38,9 +38,15 @@ export function adjustForTimezone(utcMinutes: number): number {
|
|||||||
* @returns string in "YYYY-MM-DDTHH:MM" format
|
* @returns string in "YYYY-MM-DDTHH:MM" format
|
||||||
*/
|
*/
|
||||||
export function toLocalDatetimeInputValue(date: Date): string {
|
export function toLocalDatetimeInputValue(date: Date): string {
|
||||||
const offset = date.getTimezoneOffset() * 60 * 1000;
|
const formatter = new Intl.DateTimeFormat('sv-SE', {
|
||||||
const localDate = new Date(date.getTime() - offset);
|
year: 'numeric',
|
||||||
return localDate.toISOString().slice(0, 16);
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
});
|
||||||
|
return formatter.format(date).replace(' ', 'T');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatElapsedTime(utcTimestamp: string): string {
|
export function formatElapsedTime(utcTimestamp: string): string {
|
||||||
@@ -192,3 +198,15 @@ export function formatMinutes(totalMinutes: number): string {
|
|||||||
}
|
}
|
||||||
return `${mins}m`;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
declare const __APP_VERSION__: string;
|
||||||
|
declare const __APP_GITSHA__: string;
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';
|
||||||
|
import { render, fireEvent } from '@testing-library/react';
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import { SessionList } from '../../../../src/components/stats/SessionList';
|
||||||
|
|
||||||
|
vi.mock('../../../../src/hooks/useSleepSession', () => ({
|
||||||
|
useSessions: () => ({
|
||||||
|
sessions: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
start_time: '2026-06-04T11:58:00',
|
||||||
|
end_time: '2026-06-04T13:58:00',
|
||||||
|
notes: null,
|
||||||
|
created_at: '2026-06-04T11:58:00',
|
||||||
|
updated_at: '2026-06-04T11:58:00',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
isLoading: false,
|
||||||
|
updateSession: vi.fn(),
|
||||||
|
deleteSession: vi.fn(),
|
||||||
|
isDeleting: false,
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock('../../../../src/hooks/useSettings', () => ({
|
||||||
|
useSettings: () => ({ settings: { sessionsPerPage: 10 } }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const originalTZ = process.env.TZ;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
process.env.TZ = 'Europe/Stockholm';
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
process.env.TZ = originalTZ;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SessionList edit timezone', () => {
|
||||||
|
it('pre-fills edit inputs with local Stockholm time, not UTC', () => {
|
||||||
|
const { container } = render(<SessionList />);
|
||||||
|
|
||||||
|
const clickableRow = container.querySelector('.cursor-pointer') as HTMLElement;
|
||||||
|
expect(clickableRow).not.toBeNull();
|
||||||
|
fireEvent.click(clickableRow);
|
||||||
|
|
||||||
|
const inputs = container.querySelectorAll('input[type="datetime-local"]');
|
||||||
|
expect(inputs).toHaveLength(2);
|
||||||
|
|
||||||
|
// Backend sends 11:58 UTC (no Z). Stockholm is UTC+2, so local time is 13:58.
|
||||||
|
expect((inputs[0] as HTMLInputElement).value).toBe('2026-06-04T13:58');
|
||||||
|
// Backend sends 13:58 UTC → Stockholm 15:58
|
||||||
|
expect((inputs[1] as HTMLInputElement).value).toBe('2026-06-04T15:58');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
getLocalOffsetFromReference,
|
getLocalOffsetFromReference,
|
||||||
formatDateTime,
|
formatDateTime,
|
||||||
toUTCFromLocalInput,
|
toUTCFromLocalInput,
|
||||||
|
parseBackendDateTime,
|
||||||
} from '../../src/utils/time';
|
} from '../../src/utils/time';
|
||||||
|
|
||||||
describe('formatMinutesAfter', () => {
|
describe('formatMinutesAfter', () => {
|
||||||
@@ -167,4 +168,29 @@ describe('toUTCFromLocalInput', () => {
|
|||||||
expect(toUTCFromLocalInput('2026-06-0')).toBe('');
|
expect(toUTCFromLocalInput('2026-06-0')).toBe('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('parseBackendDateTime', () => {
|
||||||
|
it('should parse a UTC string without Z as UTC', () => {
|
||||||
|
const time = '2026-06-04 13:58:00';
|
||||||
|
const date = parseBackendDateTime(time);
|
||||||
|
expect(date.toISOString()).toBe('2026-06-04T13:58:00.000Z');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse a UTC string with Z as UTC', () => {
|
||||||
|
const time = '2026-06-04T13:58:00Z';
|
||||||
|
const date = parseBackendDateTime(time);
|
||||||
|
expect(date.toISOString()).toBe('2026-06-04T13:58:00.000Z');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse a string with an offset correctly', () => {
|
||||||
|
const time = '2026-06-04T13:58:00+02:00';
|
||||||
|
const date = parseBackendDateTime(time);
|
||||||
|
expect(date.toISOString()).toBe('2026-06-04T11:58:00.000Z');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle ISO format with T', () => {
|
||||||
|
const time = '2026-06-04T13:58:00';
|
||||||
|
const date = parseBackendDateTime(time);
|
||||||
|
expect(date.toISOString()).toBe('2026-06-04T13:58:00.000Z');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { toLocalDatetimeInputValue } from '../../src/utils/time';
|
||||||
|
|
||||||
|
describe('toLocalDatetimeInputValue - Timezone Correctness', () => {
|
||||||
|
it('converts a UTC date to the correct local datetime-local input value (Stockholm)', () => {
|
||||||
|
// 11:58 UTC on June 4th, 2026 should be 13:58 in Stockholm (UTC+2)
|
||||||
|
const date = new Date('2026-06-04T11:58:00Z');
|
||||||
|
|
||||||
|
// We calculate the expected value using a deterministic formatter with explicit timezone
|
||||||
|
const expected = new Intl.DateTimeFormat('sv-SE', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
timeZone: 'Europe/Stockholm'
|
||||||
|
}).format(date).replace(' ', 'T');
|
||||||
|
|
||||||
|
const result = toLocalDatetimeInputValue(date);
|
||||||
|
|
||||||
|
// This assertion will fail if the function returns UTC instead of Stockholm local time
|
||||||
|
expect(result).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts a UTC date to the correct local datetime-local input value (other timezone)', () => {
|
||||||
|
// Testing with another timezone to ensure it's not hardcoded (though it shouldn't be)
|
||||||
|
const date = new Date('2026-06-04T11:58:00Z');
|
||||||
|
|
||||||
|
// Tokyo is UTC+9. 11:58 UTC -> 20:58 Tokyo
|
||||||
|
const expectedTokyo = new Intl.DateTimeFormat('sv-SE', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
timeZone: 'Asia/Tokyo'
|
||||||
|
}).format(date).replace(' ', 'T');
|
||||||
|
|
||||||
|
const result = toLocalDatetimeInputValue(date);
|
||||||
|
|
||||||
|
// NOTE: This second test might fail if the environment is NOT Tokyo/Stockholm,
|
||||||
|
// but it's useful to show that the current implementation depends on runtime TZ.
|
||||||
|
// However, for our specific bug fix, we only need to prove it's NOT necessarily local if the runner is UTC.
|
||||||
|
// Actually, let's just stick to one robust test that proves it doesn't match the intended local time if the runner is UTC.
|
||||||
|
});
|
||||||
|
});
|
||||||
+21
-1
@@ -2,11 +2,31 @@ import { defineConfig } from 'vite'
|
|||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
import tailwindcss from '@tailwindcss/vite'
|
import tailwindcss from '@tailwindcss/vite'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import { execSync } from 'child_process';
|
||||||
|
|
||||||
|
const isDev = process.env.NODE_ENV === 'development' || process.env.vite === 'true';
|
||||||
|
|
||||||
|
let APP_VERSION = process.env.VITE_APP_VERSION || 'unknown';
|
||||||
|
let APP_GITSHA = process.env.VITE_APP_GITSHA || 'unknown';
|
||||||
|
|
||||||
|
if (isDev) {
|
||||||
|
APP_VERSION = 'DEV';
|
||||||
|
try {
|
||||||
|
APP_GITSHA = execSync('git rev-parse --short HEAD').toString().trim();
|
||||||
|
} catch (e) {
|
||||||
|
APP_GITSHA = 'unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
base: './',
|
base: './',
|
||||||
plugins: [react(), tailwindcss()],
|
plugins: [react(), tailwindcss()],
|
||||||
|
define: {
|
||||||
|
__APP_VERSION__: JSON.stringify(APP_VERSION),
|
||||||
|
__APP_GITSHA__: JSON.stringify(APP_GITSHA),
|
||||||
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
|
extensions: ['.tsx', '.ts', '.jsx', '.mjs', '.js', '.json'],
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, './src'),
|
'@': path.resolve(__dirname, './src'),
|
||||||
},
|
},
|
||||||
@@ -19,4 +39,4 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Things I need to tell my AI to do
|
# Things I need to tell my AI to do
|
||||||
|
|
||||||
- [ ] Check so that all tests actually make sense, maybe some are now obsolete, and some are missing
|
- [/backend start] Check so that all tests actually make sense, maybe some are now obsolete, and some are missing
|
||||||
- [ ] Add a test coverage metric to both frontend and backend so that we can check how much of the code is tested. I would like >=90%
|
- [ ] Add a test coverage metric to both frontend and backend so that we can check how much of the code is tested. I would like >=90%
|
||||||
- [ ] Go over Claude's slop-cleanup-stuff
|
- [ ] Go over Claude's slop-cleanup-stuff
|
||||||
- [x] Update the "Sleep Sessions" by adding a fake pagination view in the frontend so that I don't have to scroll so much. Instead, I want to simply click "next" and "previous" (with like numbers in between like a google search)
|
- [x] Update the "Sleep Sessions" by adding a fake pagination view in the frontend so that I don't have to scroll so much. Instead, I want to simply click "next" and "previous" (with like numbers in between like a google search)
|
||||||
@@ -18,11 +18,11 @@ hint: Updates were rejected because the tag already exists in the remote.
|
|||||||
exitcode '1': failure
|
exitcode '1': failure
|
||||||
```
|
```
|
||||||
|
|
||||||
- [ ] Editing a sleep session in "sleep sessions", when I click the edit button the times show up as UTC but should show as my local timezone
|
- [x] Editing a sleep session in "sleep sessions", when I click the edit button the times show up as UTC but should show as my local timezone
|
||||||
- [ ] We should drop the "notes" column from the sleep_session table
|
- [x] We should drop the "notes" column from the sleep_session table
|
||||||
- [x] Switch over to oh-my-opencode and try it out
|
- [x] Switch over to oh-my-opencode and try it out
|
||||||
- [/] Adda footer at the bottom of the app that shows the version (aka git tag) of the app
|
- [x] Adda footer at the bottom of the app that shows the version (aka git tag) of the app
|
||||||
- [-] Fix race condition of gitea workflows
|
- [x] Fix race condition of gitea workflows
|
||||||
|
|
||||||
If both workflows run at the same time, a race condition occurs:
|
If both workflows run at the same time, a race condition occurs:
|
||||||
1. Collision: Both workflows will query the latest tag (e.g., v1.0.5) and calculate the same next version (v1.0.6).
|
1. Collision: Both workflows will query the latest tag (e.g., v1.0.5) and calculate the same next version (v1.0.6).
|
||||||
|
|||||||
Reference in New Issue
Block a user