Skip to content

feat(calendar): make Mayan new year start and seven-year anchor user-configurable - #331

Merged
liujuanjuan1984 merged 1 commit into
mainfrom
feat/mayan-new-year-configurable
Aug 26, 2026
Merged

feat(calendar): make Mayan new year start and seven-year anchor user-configurable#331
liujuanjuan1984 merged 1 commit into
mainfrom
feat/mayan-new-year-configurable

Conversation

@liujuanjuan1984

@liujuanjuan1984 liujuanjuan1984 commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

TL;DR

把玛雅 13 月亮历的「新年开始日」从硬编码 07-26(无时间日 07-25)扩展为用户偏好:/config 设置页可把任意公历「月-日」设为新年开始(默认 07-26),此日的前一天为无时间日;七年周期锚点改为精确到「年」。所有消费新年 / 无时间日 / 七年周期的路径统一经 MayanCalendarAdapter 获取,不再各处重复实现。2/29 自动按 2/28 处理,13 月亮年固定为 365 天。

Closes #330

背景与决策

  • 原实现:MayanCalendarAdapter.year_start() 硬编码 07-26;is_mayan_day_out_of_time() 硬编码 7 月 25 日;七年锚点为完整日期 calendar_seven_year_anchor_date(YYYY-MM-DD)。
  • 本次将锚点拆分为两个偏好:calendar_mayan_new_year_start(MM-DD,默认 07-26)+ calendar_seven_year_anchor_year(YYYY,默认 2025)。
  • 迁移语义:旧 calendar_seven_year_anchor_date 仅迁移「年份」到 calendar_seven_year_anchor_year;其月-日部分不再使用(新年开始日由独立偏好决定,默认 07-26),配置文件在下次写入时自动落盘新键。
  • 闰日决策(按需求评审结论):2/29 一律按 2/28 处理,避免闰日落在年度边界时的特判;无时间日 = 新年开始日的前一天(若为 2/29 则取 2/28),统计周/月粒度同时排除 2/28 与 2/29。年内普通闰日(非边界场景)保持既有 shadow-day 语义,不改变默认日历行为。

改动

  • src/lifeos_cli/config.py:新增两个偏好字段与校验器(含 02-29→02-28 归一化)、序列化与旧字段迁移。
  • src/lifeos_cli/application/calendar_adapter.pyMayanCalendarAdapter 持有 new_year_startseven_year_anchor_year;DOOT 判定收敛为 adapter 方法;get_calendar_adapter / get_calendar_period_range / iter_calendar_periods 改为接收新偏好参数。
  • src/lifeos_cli/db/services/timelog_stats.py:周/月统计排除日期改为按偏好推导(含闰日双日期排除)。
  • src/lifeos_cli/db/services/task_queries.pysrc/lifeos_web/routers/stats.pysrc/lifeos_web/routers/tasks.pysrc/lifeos_web/response_schemas/tasks.py:消费侧改传新偏好;任务列表 meta 由 seven_year_anchor_date 改为 seven_year_anchor_year + mayan_new_year_start
  • src/lifeos_web/routers/preferences.py:API 键映射与元数据更新。
  • CLI 帮助文案(en/zh):无时间日描述改为「新年开始日的前一天(默认 7 月 25 日)」。
  • 测试:自定义新年(03-01)、2/29 归一化、周/月统计排除、七年锚点年、旧配置迁移等用例;tests/config_support.py 支持写入新偏好。

契约影响

审查与验证

  • 独立审查确认:S=01-01 / 02-28 / 03-01 / 12-31 等新年开始日边界、跨年周无时间日排除、七年锚点语义(公历按年、玛雅按「锚点年 + 新年开始日」)均正确;默认 07-26 行为与改动前完全一致;未发现偏差、遗漏或冗余实现。
  • bash ./scripts/doctor.sh 全绿:lint / ruff format / dead-code / mypy / 913 tests(覆盖率 ≥74%)/ 依赖审计 / 构建通过;PostgreSQL 集成按环境跳过。

Related #329 #192 #324 lifeos-plus/lifeos-web#72

…configurable

The Mayan 13 Moon new year start (default 07-26) and the seven-year anchor
year are now user preferences instead of hardcoded constants. The Day Out
of Time is the day before the configured new year start; February 29 is
treated as February 28 so the 13-moon year stays fixed at 365 days.

- config: add calendar_mayan_new_year_start (MM-DD) and
  calendar_seven_year_anchor_year; migrate the legacy full-date anchor
- adapter: thread both preferences through get_calendar_adapter,
  get_calendar_period_range, iter_calendar_periods and the Mayan adapter
- stats: derive excluded week/month dates from preferences
- web: expose the new preference keys and task meta fields
- tests: custom new year, leap-day normalization, and stats exclusion
@liujuanjuan1984
liujuanjuan1984 merged commit e58c2a0 into main Aug 26, 2026
6 checks passed
@liujuanjuan1984
liujuanjuan1984 deleted the feat/mayan-new-year-configurable branch August 26, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

玛雅13月亮历新年开始日与七年锚点年份可配置(默认 07-26 新年 / 07-25 无时间日)

1 participant