Skip to main content

date-dimensions

将时间戳或日期时间展开为分析字段,支持 Excel 友好的返回值。需要 Python 3.10+,基础功能无需 pandas 或其他第三方包。

安装

pip install date-dimensions
pip install "date-dimensions[cn]"  # 可选,中国大陆节假日和调休
pip install "date-dimensions[tz]"  # 可选,供缺少系统时区数据的环境使用

使用

from date_dimensions import time_features, time_features_excel

row = time_features(1700000000123, unit="ms")
print(row["year"], row["month"], row["day"])  # 2023 11 15

row = time_features_excel("2024-02-12 14:35:20", include_cn_calendar=True)
print(row["is_holiday"])   # 是
print(row["is_workday"])   # 否
print(row["15min_floor"])  # 2024-02-12 14:30:00

两个函数均返回相同字段。接受数字时间戳(需指定 unit="s" 或 unit="ms")、ISO 日期时间字符串或 datetime。带时区的输入转换为上海时间,无时区输入按上海本地时间解释。

类别 字段
基础 dt、year、month、day、hour、minute、second
日历 quarter、dayofweek、day_name、is_weekend、iso_year、weekofyear、dayofyear
分桶与进度 date_only、hour_floor、15min_floor、week_start、month_start、seconds_of_day、minutes_of_day、day_progress、week_progress
月内位置 is_month_start、is_month_end、days_in_month、days_to_month_end、month_progress、is_payday_zone、ten_day_period
中国大陆日历 is_holiday、is_workday、is_in_lieu、is_makeup_workday、holiday_name
  • dayofweek 从周一的 0 到周日的 6。按周分组时使用 week_start,或使用 iso_year 和 weekofyear。
  • month_progress 为当月第几天除以当月总天数。发薪日标记命中每月 10、15、25 日。
  • include_cn_calendar=True 启用节假日查询。is_holiday 包含普通周末休息日,is_in_lieu 表示调休放假,is_makeup_workday 表示周末补班。日历查询超出依赖包覆盖年份时会报错。未开启时,这组字段为 None。
  • time_features_excel 将标记转成「是」或「否」,保留空值、数字和日期类型。时间值仍是上海本地时间,去掉时区标记后可写入 Excel。

Metadata

Release files for date-dimensions 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for date-dimensions 0.1.0
File Size Uploaded Provenance Actions
date_dimensions-0.1.0.tar.gz 5.1 kB Without provenance Details for date_dimensions-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for date-dimensions 0.1.0
File Interpreter ABI Platform Actions
date_dimensions-0.1.0-py3-none-any.whl Python 3 none any Details for date_dimensions-0.1.0-py3-none-any.whl

Total release size: 10.3 kB

Release files / date_dimensions-0.1.0.tar.gz

Download URL date_dimensions-0.1.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
15f35e168aa2adbb392d35dc577dead1fbb32e434e491af3eed6a712d1a3e0c0
BLAKE2b-256 checksum
How to use checksums
36a7d578642b8713b6b340530617b79bdca4a948b476763ebc981103ab4c610c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Release files / date_dimensions-0.1.0-py3-none-any.whl

Download URL date_dimensions-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88756ed094f95b8e56cbea8c5e59bb26bc5aad708cee3c1fc3f9845a9fc894ff
BLAKE2b-256 checksum
How to use checksums
d2971d6948802e31c4acd119eac50538d312240e7b0922ca128ecf91a2d85a9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Security for date-dimensions 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page