微信小程序页面迁移校验之前 P5任务处理之前
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# packages/shared — 跨项目共享包
|
||||
|
||||
`neozqyy-shared`:NeoZQYY Monorepo 的共享工具包,提供业务枚举、金额精度处理和时间工具。
|
||||
`neozqyy-shared`:NeoZQYY Monorepo 的共享工具包,提供业务枚举、金额精度处理、时间工具和其他通用功能。
|
||||
|
||||
## 安装
|
||||
|
||||
@@ -57,20 +57,26 @@ total = round_cny(Decimal("123.456")) # Decimal('123.46')
|
||||
|
||||
### `datetime_utils.py` — 时间工具
|
||||
|
||||
默认时区 `Asia/Shanghai`(UTC+8),与业务数据库 `timestamptz` 对齐。
|
||||
默认时区 `Asia/Shanghai`(UTC+8),与业务数据库 `timestamptz` 对齐。支持营业日计算和日期范围生成。
|
||||
|
||||
| 函数 | 说明 |
|
||||
|------|------|
|
||||
| `now_shanghai() -> datetime` | 获取上海时区当前时间 |
|
||||
| `date_range(start, end) -> list[date]` | 生成日期范围列表(含首尾) |
|
||||
| `get_business_date(dt, start_hour=8) -> date` | 根据营业日分割点计算业务日期 |
|
||||
| `format_business_date(dt, start_hour=8) -> str` | 格式化业务日期为 YYYY-MM-DD |
|
||||
|
||||
用法:
|
||||
```python
|
||||
from neozqyy_shared.datetime_utils import now_shanghai, date_range
|
||||
from datetime import date
|
||||
from neozqyy_shared.datetime_utils import now_shanghai, date_range, get_business_date
|
||||
from datetime import date, datetime
|
||||
|
||||
now = now_shanghai()
|
||||
dates = date_range(date(2026, 1, 1), date(2026, 1, 7)) # 7 天
|
||||
|
||||
# 营业日计算(凌晨 2:00 算前一天,上午 10:00 算当天)
|
||||
biz_date = get_business_date(datetime(2026, 1, 2, 2, 0)) # 2026-01-01
|
||||
biz_date = get_business_date(datetime(2026, 1, 2, 10, 0)) # 2026-01-02
|
||||
```
|
||||
|
||||
## 依赖
|
||||
|
||||
Reference in New Issue
Block a user