fix: 统一时间戳为带时区的 UTC datetime,修复跨时区部署时间显示错误#70
Merged
ZhengZhenyu merged 3 commits intoopensourceways:mainfrom Feb 24, 2026
Merged
fix: 统一时间戳为带时区的 UTC datetime,修复跨时区部署时间显示错误#70ZhengZhenyu merged 3 commits intoopensourceways:mainfrom
ZhengZhenyu merged 3 commits intoopensourceways:mainfrom
Conversation
- 新增 app/core/timezone.py:提供 utc_now()、get_app_tz()、to_app_tz() 工具函数 - 新增 APP_TIMEZONE 配置项(默认 Asia/Shanghai),控制 ICS/邮件等服务端输出的本地化时区 - 将所有模型的 DateTime 列改为 DateTime(timezone=True),default 改用 utc_now - 替换所有 datetime.utcnow() 直接调用为 utc_now()(含 services、api、security) - ICS 日历改为标准 UTC Z 格式(DTSTART:20240115T103000Z) - docker-compose.yml 添加 TZ 环境变量与 APP_TIMEZONE 联动 - 生成 Alembic 迁移 986ddbdad1d7
Contributor
CLA Signature ManualBecause of the CLA label update fail, please comment |
- 删除迁移中 _alembic_tmp_campaign_contacts 的 drop/create 操作, 避免全新数据库执行 alembic upgrade head 时报 no such table 错误 - timezone.py / ics.py:将 timezone as _tz / _tz.utc 改为 datetime.UTC (ruff UP017) - auth.py、community_dashboard.py、ics.py:修正 import 块排序 (ruff I001)
Contributor
CLA Signature ManualBecause of the CLA label update fail, please comment |
SQLite 的 DateTime(timezone=True) 在某些环境下读取时返回 naive datetime, 与 utc_now()(offset-aware)比较会引发 TypeError。 在 is_expired 中防御性处理:若 expires_at 无 tzinfo,先附加 UTC 再比较。
Contributor
CLA Signature ManualBecause of the CLA label update fail, please comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
关联 Issue:#
Checklist