px普贤教程PuXian
普贤教程 › 包参考

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_secsec
st_day_of_weekname
st_next_weekdaybase, target
st_unit_secunit
st_tokensexpr
st_parse_relativeexpr, base
st_parse_relative_okexpr, base
st_parseexpr
st_parse_okexpr
其余 8 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
st_last_weekdaybase, target
_st_is_digitc
_st_is_alphac
_st_is_int_strs
_st_parse_coreexpr, base
_st_looks_numbers
st_to_numbers
join_wordsarr

包内说明(源码头注释)

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 天)
============================================================