Use Case
Database stores UTC timestamps, but API responses should show times in user's timezone (e.g., UTC+8 for Asia/Shanghai).
Currently users see UTC times which appear 8 hours behind local time.
Proposed Solution
Implement timezone conversion in Pydantic serializers or middleware:
- Read
settings.app.timezone or user preferences
- Convert UTC timestamps to target timezone in response models
- Keep database storage in UTC
Implementation Notes
Use zoneinfo or pytz for timezone conversion.
Example: dt.astimezone(ZoneInfo('Asia/Shanghai'))
Related
Depends on reverting #88's database storage approach.
Use Case
Database stores UTC timestamps, but API responses should show times in user's timezone (e.g., UTC+8 for Asia/Shanghai).
Currently users see UTC times which appear 8 hours behind local time.
Proposed Solution
Implement timezone conversion in Pydantic serializers or middleware:
settings.app.timezoneor user preferencesImplementation Notes
Use
zoneinfoorpytzfor timezone conversion.Example:
dt.astimezone(ZoneInfo('Asia/Shanghai'))Related
Depends on reverting #88's database storage approach.