普贤教程 › 包参考
strtotime 包
英文相对时间解析
| 项 | 值 |
|---|---|
| 包名 | strtotime |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | strtotime.px |
| 分类 | 时间与日历 |
| 文件数 / 行数 | 1 / 266 |
安装与引入
bash
pxpkg init # 首次 pxpkg add strtotime@0.2.0 pxpkg install
px
import strtotime所属分类教程:时间与日历
公开接口
| 函数 | 参数 |
|---|---|
st_weekday_from_sec | sec |
st_day_of_week | name |
st_next_weekday | base, target |
st_unit_sec | unit |
st_tokens | expr |
st_parse_relative | expr, base |
st_parse_relative_ok | expr, base |
st_parse | expr |
st_parse_ok | expr |
其余 8 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
st_last_weekday | base, target |
_st_is_digit | c |
_st_is_alpha | c |
_st_is_int_str | s |
_st_parse_core | expr, base |
_st_looks_number | s |
st_to_number | s |
join_words | arr |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/strtotime — 英文相对时间解析 ------------------------------------------------------------ 纯函数库,双模式一致。 公开函数: st_parse_relative(expr, base) → int 秒(无法识别的词忽略) st_parse_relative_ok(expr, base) → Ok(秒) | Err(无法识别的词) ← 不再静默 st_parse(expr) → int 秒(base = now_sec()) st_parse_ok(expr) → Ok / Err st_weekday_from_sec(sec) → 0..6(周日=0,1970-01-01 为周四=4) st_day_of_week(name) → 0..6 / -1 st_next_weekday(base, target) → int 秒 st_unit_sec(unit) → 单位秒数 / -1(单位不认识) st_tokens(expr) → 归一化后的词元 list(调试用) 支持写法(不区分大小写、符号与数字可粘连、单位可单复数): now / today / tomorrow / yesterday +1 day / -2 hours / 3 weeks / +1day / "2 days ago" / "in 2 hours" next monday / last friday(周日=0 口径) 单位:sec/second/minute/min/hour/day/week/month(30 天)/year(365 天) ============================================================