refactor: 抽出 core/(clock store text numeric),小学版与初中版共用归一化与数值解析

This commit is contained in:
2026-11-19 08:58:57 +08:00
parent f85adf2af0
commit 5e9ca5589a
10 changed files with 312 additions and 164 deletions
+25
View File
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""时间与 ID:两个产品都用东八区,都只用「人可读的 ISO 秒」存时间。"""
from __future__ import annotations
import uuid
from datetime import date, datetime, timedelta, timezone
TZ = timezone(timedelta(hours=8))
def now() -> str:
return datetime.now(TZ).isoformat(timespec="seconds")
def today() -> str:
return datetime.now(TZ).date().isoformat()
def add_days(days: int, base: str | None = None) -> str:
d = date.fromisoformat(base) if base else date.fromisoformat(today())
return (d + timedelta(days=days)).isoformat()
def new_id(prefix: str) -> str:
return f"{prefix}_{uuid.uuid4().hex[:12]}"