refactor: 抽出 core/(clock store text numeric),小学版与初中版共用归一化与数值解析
This commit is contained in:
@@ -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]}"
|
||||
Reference in New Issue
Block a user