pyUnit_time
介绍: 基于Python实现的、中文字符串解析时间。输入当前时刻,在输入一句中文语句,
自动推导语句所表达的下一个时刻。
比如:当前时刻是2020年4月22日,输入:这个月的第三个星期日是哪天?输出:2020年4月19日。
安装
pip install pyunit-time
推导类型
- 年、月、日、时、分、秒
- 周、天
- 中国节日
- 国外特殊节日
- 农历、阳历
- 天干地支
- 二十四节气
测试
from pyunit_time import Time
def time():
"""字符字符串时间解析"""
print(Time('2020-4-22 00:00:00').parse('这个月的第三个星期天'))
# [{'key': '这个月第3个星期天', 'keyDate': '2020-04-19 00:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('前2年的国庆节的后一天晚上8点半'))
# [{'key': '前2年国庆节后1天晚上8点半', 'keyDate': '2018-09-30 20:30:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('上上个月'))
# [{'key': '上上个月', 'keyDate': '2020-02-22 00:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('今天晚上8点'))
# [{'key': '今天晚上8点', 'keyDate': '2020-04-22 20:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('今年儿童节晚上九点一刻'))
# [{'key': '今年儿童节晚上9点1刻', 'keyDate': '2020-06-01 21:15:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('今天中午十二点'))
# [{'key': '今天中午12点', 'keyDate': '2020-04-22 12:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('明年春节'))
# [{'key': '明年春节', 'keyDate': '2021-02-12 00:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('明年的感恩节'))
# [{'key': '明年感恩节', 'keyDate': '2021-11-25 00:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('下3个星期1早上7点半'))
# [{'key': '下3个星期1早上7点半', 'keyDate': '2020-05-11 07:30:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('今年的大寒'))
# [{'key': '今年大寒', 'keyDate': '2021-01-20 00:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('2019年12月'))
# [{'key': '2019年12月', 'keyDate': '2019-12-01 00:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('8年前'))
# [{'key': '8年前', 'keyDate': '2012-04-22 00:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('三天以后'))
# [{'key': '3天以后', 'keyDate': '2020-04-25 00:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('三天之内的下午3点'))
# [{'key': '3天之内下午3点', 'keyDate': '2020-04-25 15:00:00', 'baseDate': '2020-04-22 00:00:00'}]
print(Time('2020-4-22 00:00:00').parse('后三天的下午4点56秒'))
# [{'key': '后3天下午4点56秒', 'keyDate': '2020-04-25 16:00:56', 'baseDate': '2020-04-22 00:00:00'}]
if __name__ == '__main__':
time()
Metadata
Release files for pyunit-time 2024.7.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyunit_time-2024.7.3.tar.gz | 297.9 kB | Without provenance | Details for pyunit_time-2024.7.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyunit_time-2024.7.3-py3-none-any.whl | Python 3 | none | any | Details for pyunit_time-2024.7.3-py3-none-any.whl |
Total release size: 603.5 kB
Release files / pyunit_time-2024.7.3.tar.gz
| Download URL | pyunit_time-2024.7.3.tar.gz |
|---|---|
| Size | 297.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c0d41814c97ab9fe5f5c0772901362d93a89f862e0f17fed8a9ba2b8db6169c1
|
|
BLAKE2b-256 checksum How to use checksums |
e87e96611ae6c76636e08af568070aeb03093a37a33be369bd6fc538dcc019ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.18
|
Release files / pyunit_time-2024.7.3-py3-none-any.whl
| Download URL | pyunit_time-2024.7.3-py3-none-any.whl |
|---|---|
| Size | 305.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72489fd95e79a7f42775d934e35bd522ead3ca7595d565fd715ccc50cea1314d
|
|
BLAKE2b-256 checksum How to use checksums |
3c3275005c52fb9f302b85e9ecadd2ce8bef831140950560a68806f517fa516a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.18
|
Security for pyunit-time 2024.7.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.