mirror of
https://github.com/Oak-and-Sprout/sprout-track.git
synced 2026-05-03 13:41:02 -05:00
4.6 KiB
4.6 KiB
Timezone Refactoring: File Changes
This document outlines the specific files that need to be modified as part of the timezone refactoring project, along with the changes required for each file.
Files to Modify
Server-Side Files
-
app/api/utils/timezone.ts- Current state: Contains a mix of server-side and client-side timezone utilities
- Required changes:
- Simplify to focus on core UTC conversion functions
- Add proper error handling
- Add comprehensive JSDoc comments
- Remove client-specific functions
-
app/api/timezone/route.ts- Current state: Provides API endpoints for timezone operations and conversions
- Required changes:
- Simplify to only provide timezone information
- Remove redundant conversion endpoints
- Consider removing entirely if no longer needed
-
API Route Files:
- Files:
app/api/feed-log/route.tsapp/api/sleep-log/route.tsapp/api/diaper-log/route.tsapp/api/note/route.tsapp/api/bath-log/route.tsapp/api/pump-log/route.ts
- Current state: Store dates as local time and use
toLocaleString()for responses - Required changes:
- Update to store dates in UTC
- Use ISO strings for date serialization in responses
- Use the timezone utilities for all date operations
- Files:
Client-Side Files
-
app/context/timezone.tsx- Current state: Provides client-side timezone utilities but lacks comprehensive formatting functions
- Required changes:
- Enhance with comprehensive formatting functions
- Add functions for common operations
- Implement proper DST handling
- Remove server-specific functions
-
Component Utilities:
- Files:
src/components/ui/activity-tile/activity-tile-utils.tssrc/components/Timeline/utils.tsx
- Current state: Implement their own timezone handling
- Required changes:
- Refactor to use timezone context
- Remove redundant timezone handling
- Files:
-
UI Components:
- Files:
src/components/ui/status-bubble/index.tsxsrc/components/ActivityTileGroup/index.tsxsrc/components/ui/activity-tile/index.tsxsrc/components/ui/activity-tile/activity-tile-content.tsx
- Current state: Some use the timezone context, others implement their own logic
- Required changes:
- Update to consistently use timezone context
- Remove local timezone handling
- Files:
-
Form Components:
- Files:
src/components/forms/FeedForm/index.tsxsrc/components/forms/SleepForm/index.tsxsrc/components/forms/DiaperForm/index.tsxsrc/components/forms/NoteForm/index.tsxsrc/components/forms/BathForm/index.tsxsrc/components/forms/PumpForm/index.tsx
- Current state: Handle dates inconsistently
- Required changes:
- Update to use timezone context for all date operations
- Ensure consistent date handling across all forms
- Files:
Documentation Files
-
app/api/utils/timezone.README.md- Current state: May be outdated or incomplete
- Required changes:
- Update with new architecture
- Document server-side timezone utilities
- Add usage examples
-
app/context/timezone.README.md- Current state: May be outdated or incomplete
- Required changes:
- Update with new architecture
- Document client-side timezone context
- Add usage examples
New Files to Create
- Migration Script:
- Path:
scripts/migrate-dates-to-utc.ts - Purpose: Convert existing dates in the database to UTC
- Implementation: Use the new timezone utilities to convert dates
- Path:
Files to Remove
app/api/timezone/route.ts(if no longer needed)- Current state: Provides API endpoints for timezone operations
- Reason for removal: Redundant with client-side timezone detection
Detailed Changes by Phase
Phase 1: Server-Side Standardization
- Update
app/api/utils/timezone.ts - Update API route files to store dates in UTC
- Simplify
app/api/timezone/route.ts
Phase 2: Client-Side Enhancement
- Update
app/context/timezone.tsx - Update component utilities to use timezone context
Phase 3: Component Updates
- Update UI components to use timezone context
- Update form components to use timezone context
Phase 4: Testing and Documentation
- Create test cases for timezone handling
- Update documentation files
Phase 5: Migration and Cleanup
- Create and run migration script
- Remove redundant code and files