staran 1.0.1__py3-none-any.whl → 1.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- staran/__init__.py +57 -5
- staran/date/__init__.py +37 -0
- staran/date/core.py +549 -0
- staran/date/examples/__init__.py +11 -0
- staran/date/examples/basic_usage.py +177 -0
- staran/date/tests/__init__.py +11 -0
- staran/date/tests/run_tests.py +109 -0
- staran/{tools/tests/test_date.py → date/tests/test_core.py} +289 -335
- staran/date/utils/__init__.py +11 -0
- staran/date/utils/helpers.py +203 -0
- staran-1.0.4.dist-info/METADATA +145 -0
- staran-1.0.4.dist-info/RECORD +15 -0
- staran/tools/__init__.py +0 -43
- staran/tools/date.py +0 -405
- staran/tools/tests/__init__.py +0 -119
- staran/tools/tests/run_tests.py +0 -241
- staran/tools/tests/test_api_compatibility.py +0 -319
- staran/tools/tests/test_logging.py +0 -402
- staran-1.0.1.dist-info/METADATA +0 -37
- staran-1.0.1.dist-info/RECORD +0 -13
- {staran-1.0.1.dist-info → staran-1.0.4.dist-info}/WHEEL +0 -0
- {staran-1.0.1.dist-info → staran-1.0.4.dist-info}/licenses/LICENSE +0 -0
- {staran-1.0.1.dist-info → staran-1.0.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,203 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
"""
|
5
|
+
日期处理辅助工具
|
6
|
+
==============
|
7
|
+
|
8
|
+
提供日期处理相关的辅助函数和常量。
|
9
|
+
"""
|
10
|
+
|
11
|
+
import calendar
|
12
|
+
from typing import List, Tuple
|
13
|
+
|
14
|
+
# 常量定义
|
15
|
+
WEEKDAYS_ZH = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
|
16
|
+
WEEKDAYS_EN = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
|
17
|
+
MONTHS_ZH = ['一月', '二月', '三月', '四月', '五月', '六月',
|
18
|
+
'七月', '八月', '九月', '十月', '十一月', '十二月']
|
19
|
+
MONTHS_EN = ['January', 'February', 'March', 'April', 'May', 'June',
|
20
|
+
'July', 'August', 'September', 'October', 'November', 'December']
|
21
|
+
|
22
|
+
|
23
|
+
def get_quarter(month: int) -> int:
|
24
|
+
"""获取月份对应的季度
|
25
|
+
|
26
|
+
Args:
|
27
|
+
month: 月份 (1-12)
|
28
|
+
|
29
|
+
Returns:
|
30
|
+
季度 (1-4)
|
31
|
+
"""
|
32
|
+
return (month - 1) // 3 + 1
|
33
|
+
|
34
|
+
|
35
|
+
def get_quarter_months(quarter: int) -> List[int]:
|
36
|
+
"""获取季度包含的月份
|
37
|
+
|
38
|
+
Args:
|
39
|
+
quarter: 季度 (1-4)
|
40
|
+
|
41
|
+
Returns:
|
42
|
+
月份列表
|
43
|
+
"""
|
44
|
+
if quarter == 1:
|
45
|
+
return [1, 2, 3]
|
46
|
+
elif quarter == 2:
|
47
|
+
return [4, 5, 6]
|
48
|
+
elif quarter == 3:
|
49
|
+
return [7, 8, 9]
|
50
|
+
elif quarter == 4:
|
51
|
+
return [10, 11, 12]
|
52
|
+
else:
|
53
|
+
raise ValueError("季度必须在1-4之间")
|
54
|
+
|
55
|
+
|
56
|
+
def is_business_day(year: int, month: int, day: int) -> bool:
|
57
|
+
"""判断是否为工作日(简单版本,仅考虑周末)
|
58
|
+
|
59
|
+
Args:
|
60
|
+
year: 年
|
61
|
+
month: 月
|
62
|
+
day: 日
|
63
|
+
|
64
|
+
Returns:
|
65
|
+
是否为工作日
|
66
|
+
"""
|
67
|
+
import datetime
|
68
|
+
date = datetime.date(year, month, day)
|
69
|
+
return date.weekday() < 5 # 0-4为周一到周五
|
70
|
+
|
71
|
+
|
72
|
+
def get_week_range(year: int, month: int, day: int) -> Tuple[Tuple[int, int, int], Tuple[int, int, int]]:
|
73
|
+
"""获取指定日期所在周的开始和结束日期
|
74
|
+
|
75
|
+
Args:
|
76
|
+
year: 年
|
77
|
+
month: 月
|
78
|
+
day: 日
|
79
|
+
|
80
|
+
Returns:
|
81
|
+
((开始年, 开始月, 开始日), (结束年, 结束月, 结束日))
|
82
|
+
"""
|
83
|
+
import datetime
|
84
|
+
date = datetime.date(year, month, day)
|
85
|
+
|
86
|
+
# 计算周一(周开始)
|
87
|
+
days_since_monday = date.weekday()
|
88
|
+
monday = date - datetime.timedelta(days=days_since_monday)
|
89
|
+
|
90
|
+
# 计算周日(周结束)
|
91
|
+
sunday = monday + datetime.timedelta(days=6)
|
92
|
+
|
93
|
+
return ((monday.year, monday.month, monday.day),
|
94
|
+
(sunday.year, sunday.month, sunday.day))
|
95
|
+
|
96
|
+
|
97
|
+
def format_weekday(weekday: int, lang: str = 'zh') -> str:
|
98
|
+
"""格式化星期几
|
99
|
+
|
100
|
+
Args:
|
101
|
+
weekday: 星期几 (0=星期一, 6=星期日)
|
102
|
+
lang: 语言 ('zh'=中文, 'en'=英文)
|
103
|
+
|
104
|
+
Returns:
|
105
|
+
格式化的星期几字符串
|
106
|
+
"""
|
107
|
+
if lang == 'zh':
|
108
|
+
return WEEKDAYS_ZH[weekday]
|
109
|
+
elif lang == 'en':
|
110
|
+
return WEEKDAYS_EN[weekday]
|
111
|
+
else:
|
112
|
+
raise ValueError("语言必须是 'zh' 或 'en'")
|
113
|
+
|
114
|
+
|
115
|
+
def format_month(month: int, lang: str = 'zh') -> str:
|
116
|
+
"""格式化月份
|
117
|
+
|
118
|
+
Args:
|
119
|
+
month: 月份 (1-12)
|
120
|
+
lang: 语言 ('zh'=中文, 'en'=英文)
|
121
|
+
|
122
|
+
Returns:
|
123
|
+
格式化的月份字符串
|
124
|
+
"""
|
125
|
+
if lang == 'zh':
|
126
|
+
return MONTHS_ZH[month - 1]
|
127
|
+
elif lang == 'en':
|
128
|
+
return MONTHS_EN[month - 1]
|
129
|
+
else:
|
130
|
+
raise ValueError("语言必须是 'zh' 或 'en'")
|
131
|
+
|
132
|
+
|
133
|
+
def calculate_age(birth_year: int, birth_month: int, birth_day: int,
|
134
|
+
current_year: int, current_month: int, current_day: int) -> int:
|
135
|
+
"""计算年龄
|
136
|
+
|
137
|
+
Args:
|
138
|
+
birth_year: 出生年
|
139
|
+
birth_month: 出生月
|
140
|
+
birth_day: 出生日
|
141
|
+
current_year: 当前年
|
142
|
+
current_month: 当前月
|
143
|
+
current_day: 当前日
|
144
|
+
|
145
|
+
Returns:
|
146
|
+
年龄
|
147
|
+
"""
|
148
|
+
age = current_year - birth_year
|
149
|
+
|
150
|
+
# 如果还没到生日,年龄减1
|
151
|
+
if (current_month, current_day) < (birth_month, birth_day):
|
152
|
+
age -= 1
|
153
|
+
|
154
|
+
return age
|
155
|
+
|
156
|
+
|
157
|
+
def get_zodiac_sign(month: int, day: int) -> str:
|
158
|
+
"""获取星座
|
159
|
+
|
160
|
+
Args:
|
161
|
+
month: 月份
|
162
|
+
day: 日期
|
163
|
+
|
164
|
+
Returns:
|
165
|
+
星座名称
|
166
|
+
"""
|
167
|
+
if (month == 3 and day >= 21) or (month == 4 and day <= 19):
|
168
|
+
return "白羊座"
|
169
|
+
elif (month == 4 and day >= 20) or (month == 5 and day <= 20):
|
170
|
+
return "金牛座"
|
171
|
+
elif (month == 5 and day >= 21) or (month == 6 and day <= 20):
|
172
|
+
return "双子座"
|
173
|
+
elif (month == 6 and day >= 21) or (month == 7 and day <= 22):
|
174
|
+
return "巨蟹座"
|
175
|
+
elif (month == 7 and day >= 23) or (month == 8 and day <= 22):
|
176
|
+
return "狮子座"
|
177
|
+
elif (month == 8 and day >= 23) or (month == 9 and day <= 22):
|
178
|
+
return "处女座"
|
179
|
+
elif (month == 9 and day >= 23) or (month == 10 and day <= 22):
|
180
|
+
return "天秤座"
|
181
|
+
elif (month == 10 and day >= 23) or (month == 11 and day <= 21):
|
182
|
+
return "天蝎座"
|
183
|
+
elif (month == 11 and day >= 22) or (month == 12 and day <= 21):
|
184
|
+
return "射手座"
|
185
|
+
elif (month == 12 and day >= 22) or (month == 1 and day <= 19):
|
186
|
+
return "摩羯座"
|
187
|
+
elif (month == 1 and day >= 20) or (month == 2 and day <= 18):
|
188
|
+
return "水瓶座"
|
189
|
+
else: # (month == 2 and day >= 19) or (month == 3 and day <= 20)
|
190
|
+
return "双鱼座"
|
191
|
+
|
192
|
+
|
193
|
+
def get_chinese_zodiac(year: int) -> str:
|
194
|
+
"""获取生肖
|
195
|
+
|
196
|
+
Args:
|
197
|
+
year: 年份
|
198
|
+
|
199
|
+
Returns:
|
200
|
+
生肖名称
|
201
|
+
"""
|
202
|
+
zodiacs = ['猴', '鸡', '狗', '猪', '鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊']
|
203
|
+
return zodiacs[year % 12]
|
@@ -0,0 +1,145 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: staran
|
3
|
+
Version: 1.0.4
|
4
|
+
Summary: staran - 轻量级Python日期工具库
|
5
|
+
Home-page: https://github.com/starlxa/staran
|
6
|
+
Author: StarAn
|
7
|
+
Author-email: starlxa@icloud.com
|
8
|
+
License: MIT
|
9
|
+
Project-URL: Bug Reports, https://github.com/starlxa/staran/issues
|
10
|
+
Project-URL: Source, https://github.com/starlxa/staran
|
11
|
+
Keywords: date datetime utilities time-processing
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
13
|
+
Classifier: Intended Audience :: Developers
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
15
|
+
Classifier: Topic :: Utilities
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
23
|
+
Classifier: Operating System :: OS Independent
|
24
|
+
Requires-Python: >=3.7
|
25
|
+
Description-Content-Type: text/markdown
|
26
|
+
License-File: LICENSE
|
27
|
+
Dynamic: author
|
28
|
+
Dynamic: author-email
|
29
|
+
Dynamic: classifier
|
30
|
+
Dynamic: description
|
31
|
+
Dynamic: description-content-type
|
32
|
+
Dynamic: home-page
|
33
|
+
Dynamic: keywords
|
34
|
+
Dynamic: license
|
35
|
+
Dynamic: license-file
|
36
|
+
Dynamic: project-url
|
37
|
+
Dynamic: requires-python
|
38
|
+
Dynamic: summary
|
39
|
+
|
40
|
+
# Staran v1.0.4 - 企业级多功能工具库
|
41
|
+
|
42
|
+
[](https://python.org)
|
43
|
+
[](LICENSE)
|
44
|
+
[](#测试)
|
45
|
+
|
46
|
+
一个现代化的Python多功能工具库,为企业应用提供一系列高质量、零依赖的解决方案。
|
47
|
+
|
48
|
+
## 🚀 核心理念
|
49
|
+
|
50
|
+
`staran` 旨在成为一个可扩展的工具库,包含多个独立的、高质量的模块。每个模块都专注于解决特定领域的问题,并遵循统一的设计标准。
|
51
|
+
|
52
|
+
### 当前模块
|
53
|
+
- **`date`**: 企业级日期处理工具 (v1.0.4)
|
54
|
+
|
55
|
+
### 未来模块
|
56
|
+
- `file`: 文件处理工具
|
57
|
+
- `crypto`: 加解密工具
|
58
|
+
- ...
|
59
|
+
|
60
|
+
## 📁 项目结构
|
61
|
+
|
62
|
+
```
|
63
|
+
staran/
|
64
|
+
├── __init__.py # 主包入口
|
65
|
+
└── date/ # 日期工具模块
|
66
|
+
├── __init__.py # date模块入口
|
67
|
+
├── core.py # 核心Date类
|
68
|
+
├── api_reference.md # API参考文档
|
69
|
+
└── tests/ # date模块的测试
|
70
|
+
```
|
71
|
+
|
72
|
+
---
|
73
|
+
|
74
|
+
## ✨ `date` 模块 - 企业级日期处理
|
75
|
+
|
76
|
+
`date` 模块提供了强大的日期处理功能,具有统一API、智能格式记忆和企业级日志等特性。
|
77
|
+
|
78
|
+
### 快速开始
|
79
|
+
|
80
|
+
#### 安装
|
81
|
+
|
82
|
+
```bash
|
83
|
+
pip install staran
|
84
|
+
```
|
85
|
+
|
86
|
+
#### 基本用法
|
87
|
+
|
88
|
+
```python
|
89
|
+
from staran.date import Date, today
|
90
|
+
|
91
|
+
# 快速创建日期
|
92
|
+
today_date = today()
|
93
|
+
print(today_date) # 2025-07-29
|
94
|
+
|
95
|
+
# 从字符串创建
|
96
|
+
date = Date.from_string("20250415")
|
97
|
+
print(date.format_chinese()) # 2025年04月15日
|
98
|
+
|
99
|
+
# 日期运算(保持格式)
|
100
|
+
future = date.add_months(3)
|
101
|
+
print(future) # 20250715
|
102
|
+
```
|
103
|
+
|
104
|
+
### 📚 文档
|
105
|
+
|
106
|
+
有关 `date` 模块的完整 API 和用法,请参阅 **[`date` 模块 API 参考](staran/date/api_reference.md)**。
|
107
|
+
|
108
|
+
## 🧪 测试
|
109
|
+
|
110
|
+
运行 `date` 模块的完整测试套件:
|
111
|
+
|
112
|
+
```bash
|
113
|
+
# 彩色测试输出
|
114
|
+
python -m staran.date.tests.run_tests
|
115
|
+
|
116
|
+
# 标准unittest
|
117
|
+
python -m unittest staran.date.tests.test_core
|
118
|
+
```
|
119
|
+
|
120
|
+
测试覆盖率:**100%**(64项测试,涵盖所有功能模块)
|
121
|
+
|
122
|
+
## 📄 许可证
|
123
|
+
|
124
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件
|
125
|
+
|
126
|
+
## 🤝 贡献
|
127
|
+
|
128
|
+
欢迎为 `staran` 贡献新的工具模块或改进现有模块!
|
129
|
+
|
130
|
+
1. Fork 本项目
|
131
|
+
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
|
132
|
+
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
|
133
|
+
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
134
|
+
5. 开启Pull Request
|
135
|
+
|
136
|
+
## 📞 支持
|
137
|
+
|
138
|
+
- 📧 Email: simon@wsi.hk
|
139
|
+
- 📖 文档: https://staran.readthedocs.io/
|
140
|
+
- 🐛 问题报告: https://github.com/starlxa/staran/issues
|
141
|
+
|
142
|
+
---
|
143
|
+
|
144
|
+
**Staran v1.0.4** - 让工具开发变得简单而强大 ✨
|
145
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
staran/__init__.py,sha256=tHIqYKvkrhwhUKQ-H2DLHj0JjvOY5QbkTrk7_pfLaFI,1172
|
2
|
+
staran/date/__init__.py,sha256=nm6tx-Qq9ntiwPGG4ieDTSl8MhTn3KugZyGLfUUBiaA,615
|
3
|
+
staran/date/core.py,sha256=E-fs3lfX4ZVeh0YN8Vjmt3wv-UOrrfW8bETj-R8Js8E,18595
|
4
|
+
staran/date/examples/__init__.py,sha256=5q6uxzeIhPcFo64gXybEozx4E4lt8TEEibFC-dF_EV0,163
|
5
|
+
staran/date/examples/basic_usage.py,sha256=hsQZaMRR6tY9krLjmYrH7GrMkk2cGapY-bfjwsL_6YQ,4738
|
6
|
+
staran/date/tests/__init__.py,sha256=oYQFFa4lv_68398OrMGk4CMX_4XX-9KuPHTflhkLmbo,171
|
7
|
+
staran/date/tests/run_tests.py,sha256=Ix4qm_gF5blbSfVx05Deoml35BdQ7eIYERRPSw5AAP4,3424
|
8
|
+
staran/date/tests/test_core.py,sha256=V7aTXAjNaHrdSWHE5aoem2u8s00ilI-Skbxo0fgqjvk,16444
|
9
|
+
staran/date/utils/__init__.py,sha256=W5DkeslSOINF7kq6wFz3l16fUmGI0XALNuJAALQeLLM,142
|
10
|
+
staran/date/utils/helpers.py,sha256=9TlebdCr-YD4vrXjTFMXDG413gbSFwdUNyivAarIp5M,5553
|
11
|
+
staran-1.0.4.dist-info/licenses/LICENSE,sha256=2EmsBIyDCono4iVXNpv5_px9qt2b7hfPq1WuyGVMNP4,1361
|
12
|
+
staran-1.0.4.dist-info/METADATA,sha256=8attivCG0SOx2lM7RpP6XJj1fgcEkjMxgQX5uBfcS-U,4020
|
13
|
+
staran-1.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
14
|
+
staran-1.0.4.dist-info/top_level.txt,sha256=NOUZtXSh5oSIEjHrC0lQ9WmoKtD010Q00dghWyag-Zs,7
|
15
|
+
staran-1.0.4.dist-info/RECORD,,
|
staran/tools/__init__.py
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
"""
|
5
|
-
Staran Tools - 日期工具模块
|
6
|
-
========================
|
7
|
-
|
8
|
-
提供智能的日期处理功能。
|
9
|
-
|
10
|
-
Date类 - 智能日期处理:
|
11
|
-
- 格式记忆:根据输入自动设置默认格式
|
12
|
-
- 多种创建方式:支持字符串、参数、关键字等
|
13
|
-
- 丰富格式化:提供多种预设输出格式
|
14
|
-
- 日期运算:支持天数、月数的加减运算
|
15
|
-
- 标准比较:支持日期间的比较操作
|
16
|
-
|
17
|
-
示例::
|
18
|
-
|
19
|
-
from staran.tools import Date
|
20
|
-
|
21
|
-
# 创建日期
|
22
|
-
date = Date('202504') # 自动记住YYYYMM格式
|
23
|
-
full_date = Date('20250415') # 自动记住YYYYMMDD格式
|
24
|
-
|
25
|
-
# 运算保持格式
|
26
|
-
next_month = date.add_months(1) # 输出: 202505
|
27
|
-
|
28
|
-
# 多种格式输出
|
29
|
-
print(date.format_chinese()) # 2025年04月01日
|
30
|
-
"""
|
31
|
-
|
32
|
-
# 导入date模块的主要类和函数
|
33
|
-
from .date import Date
|
34
|
-
|
35
|
-
# 主要导出
|
36
|
-
__all__ = [
|
37
|
-
'Date'
|
38
|
-
]
|
39
|
-
|
40
|
-
# 模块信息
|
41
|
-
__version__ = '1.0.1'
|
42
|
-
__author__ = 'StarAn'
|
43
|
-
__description__ = 'Lightweight Python date utilities with smart format memory'
|