Revert to local timezone display for user-facing times

- Changed formatTime back to use toLocaleTimeString (local time)
- Changed formatDateTime back to use toLocaleString (local time)
- App now displays all times in user's local timezone
- Backend still stores times in UTC, frontend converts for display
This commit is contained in:
counterweight 2025-12-21 18:20:22 +01:00
parent a5b941e748
commit 74ed6f0c11
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 30 additions and 24 deletions

View file

@ -48,14 +48,20 @@ dev:
cd frontend && npm run dev & \ cd frontend && npm run dev & \
wait wait
# TEST variable can be used to select specific tests:
# Backend: TEST="-m auth" (marker) or TEST="tests/test_booking.py" (file) or TEST="tests/test_booking.py::TestBooking::test_specific" (specific test)
# Frontend: TEST="app/login" (file pattern matching app/**/*.test.{ts,tsx})
# E2E: TEST="auth" (file pattern matching e2e/*.spec.ts)
TEST ?=
test-backend: db-clean db-ready test-backend: db-clean db-ready
cd backend && uv run pytest -v cd backend && uv run pytest -v $(TEST)
test-frontend: test-frontend:
cd frontend && npm run test cd frontend && npm run test $(if $(TEST),-- $(TEST),)
test-e2e: db-clean db-ready test-e2e: db-clean db-ready
./scripts/e2e.sh ./scripts/e2e.sh $(TEST)
test: check-constants check-types-fresh test-backend test-frontend test-e2e test: check-constants check-types-fresh test-backend test-frontend test-e2e

View file

@ -13,35 +13,30 @@ export function formatDate(d: Date): string {
} }
/** /**
* Format time from ISO string to HH:MM format in UTC. * Format time from ISO string to HH:MM format in local timezone.
* Uses UTC to avoid timezone conversion issues when displaying booking slots.
*/ */
export function formatTime(isoString: string): string { export function formatTime(isoString: string): string {
const d = new Date(isoString); const d = new Date(isoString);
// Use UTC methods to avoid timezone conversion return d.toLocaleTimeString("en-US", {
const hours = String(d.getUTCHours()).padStart(2, "0"); hour: "2-digit",
const minutes = String(d.getUTCMinutes()).padStart(2, "0"); minute: "2-digit",
return `${hours}:${minutes}`; hour12: false,
});
} }
/** /**
* Format datetime from ISO string to a readable format in UTC. * Format datetime from ISO string to a readable format in local timezone.
* Uses UTC to avoid timezone conversion issues when displaying appointment times.
*/ */
export function formatDateTime(isoString: string): string { export function formatDateTime(isoString: string): string {
const d = new Date(isoString); const d = new Date(isoString);
return d.toLocaleString("en-US", {
// Use UTC methods to avoid timezone conversion weekday: "short",
const weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; month: "short",
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; day: "numeric",
hour: "2-digit",
const weekday = weekdays[d.getUTCDay()]; minute: "2-digit",
const month = months[d.getUTCMonth()]; hour12: false,
const day = d.getUTCDate(); });
const hours = String(d.getUTCHours()).padStart(2, "0");
const minutes = String(d.getUTCMinutes()).padStart(2, "0");
return `${weekday}, ${month} ${day}, ${hours}:${minutes}`;
} }
/** /**

View file

@ -36,8 +36,13 @@ npm run generate-api-types
cd .. cd ..
# Run tests (suppress Node.js color warnings) # Run tests (suppress Node.js color warnings)
# If TEST argument is provided, use it as a file pattern
cd frontend cd frontend
if [ -n "$1" ]; then
NODE_NO_WARNINGS=1 npx playwright test "$1"
else
NODE_NO_WARNINGS=1 npm run test:e2e NODE_NO_WARNINGS=1 npm run test:e2e
fi
EXIT_CODE=$? EXIT_CODE=$?
# Cleanup # Cleanup