staran 1.0.0__py3-none-any.whl → 1.0.3__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.
@@ -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,198 @@
1
+ Metadata-Version: 2.4
2
+ Name: staran
3
+ Version: 1.0.3
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.3 - 企业级多功能工具库
41
+
42
+ [![Python Version](https://img.shields.io/badge/python-3.7%2B-blue.svg)](https://python.org)
43
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
44
+ [![Test Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)](#测试)
45
+
46
+ 一个现代化的Python多功能工具库,为企业应用提供一系列高质量、零依赖的解决方案。
47
+
48
+ ## 🚀 核心理念
49
+
50
+ `staran` 旨在成为一个可扩展的工具库,包含多个独立的、高质量的模块。每个模块都专注于解决特定领域的问题,并遵循统一的设计标准。
51
+
52
+ ### 当前模块
53
+ - **`date`**: 企业级日期处理工具 (v1.0.3)
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
+ ├── tests/ # date模块的测试
69
+ ├── utils/ # date模块的工具函数
70
+ └── examples/ # date模块的示例
71
+ ```
72
+
73
+ ---
74
+
75
+ ## ✨ `date` 模块 - 企业级日期处理
76
+
77
+ `date` 模块提供了强大的日期处理功能,具有统一API、智能格式记忆和企业级日志等特性。
78
+
79
+ ### 快速开始
80
+
81
+ #### 安装
82
+
83
+ ```bash
84
+ pip install staran
85
+ ```
86
+
87
+ #### 基本用法
88
+
89
+ ```python
90
+ from staran.date import Date, today
91
+
92
+ # 快速创建日期
93
+ today_date = today()
94
+ print(today_date) # 2025-07-29
95
+
96
+ # 从字符串创建
97
+ date = Date.from_string("20250415")
98
+ print(date.format_chinese()) # 2025年04月15日
99
+
100
+ # 日期运算(保持格式)
101
+ future = date.add_months(3)
102
+ print(future) # 20250715
103
+ ```
104
+
105
+ ### 📚 `date` 模块详细文档
106
+
107
+ #### 1. 创建日期对象
108
+
109
+ ```python
110
+ from staran.date import Date
111
+
112
+ # 多种创建方式
113
+ d1 = Date(2025, 4, 15) # 从参数
114
+ d2 = Date.from_string("202504") # 从字符串(智能解析)
115
+ d3 = Date.from_string("20250415") # 完整格式
116
+ d4 = Date.from_string("2025") # 年份格式
117
+ d5 = Date.today() # 今日
118
+ ```
119
+
120
+ #### 2. 智能格式记忆
121
+
122
+ `date` 模块会记住输入格式,并在运算后保持相同格式:
123
+
124
+ ```python
125
+ year_date = Date.from_string("2025")
126
+ print(year_date.add_years(1)) # 2026
127
+
128
+ month_date = Date.from_string("202504")
129
+ print(month_date.add_months(2)) # 202506
130
+
131
+ full_date = Date.from_string("20250415")
132
+ print(full_date.add_days(10)) # 20250425
133
+ ```
134
+
135
+ #### 3. 统一API命名
136
+
137
+ `date` 模块遵循统一的API命名规范,如 `from_*`, `to_*`, `get_*`, `is_*`, `add_*/subtract_*` 等,具体请参考 `staran/date/examples/basic_usage.py`。
138
+
139
+ #### 4. 异常处理
140
+
141
+ `date` 模块提供了一套清晰的异常类,以便更好地处理错误:
142
+
143
+ - `DateError`: 所有日期相关错误的基类。
144
+ - `InvalidDateFormatError`: 当输入字符串格式不正确时抛出。
145
+ - `InvalidDateValueError`: 当日期值无效时(如月份为13)抛出。
146
+
147
+ **示例:**
148
+ ```python
149
+ from staran.date import Date, InvalidDateValueError, InvalidDateFormatError
150
+
151
+ try:
152
+ Date("2025", 13, 1)
153
+ except InvalidDateValueError as e:
154
+ print(e)
155
+
156
+ try:
157
+ Date("invalid-date")
158
+ except InvalidDateFormatError as e:
159
+ print(e)
160
+ ```
161
+
162
+ ## 🧪 测试
163
+
164
+ 运行 `date` 模块的完整测试套件:
165
+
166
+ ```bash
167
+ # 彩色测试输出
168
+ python -m staran.date.tests.run_tests
169
+
170
+ # 标准unittest
171
+ python -m unittest staran.date.tests.test_core
172
+ ```
173
+
174
+ 测试覆盖率:**100%**(64项测试,涵盖所有功能模块)
175
+
176
+ ## 📄 许可证
177
+
178
+ MIT License - 详见 [LICENSE](LICENSE) 文件
179
+
180
+ ## 🤝 贡献
181
+
182
+ 欢迎为 `staran` 贡献新的工具模块或改进现有模块!
183
+
184
+ 1. Fork 本项目
185
+ 2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
186
+ 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
187
+ 4. 推送到分支 (`git push origin feature/AmazingFeature`)
188
+ 5. 开启Pull Request
189
+
190
+ ## 📞 支持
191
+
192
+ - 📧 Email: team@staran.dev
193
+ - 📖 文档: https://staran.readthedocs.io/
194
+ - 🐛 问题报告: https://github.com/starlxa/staran/issues
195
+
196
+ ---
197
+
198
+ **Staran v1.0.3** - 让工具开发变得简单而强大 ✨
@@ -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.3.dist-info/licenses/LICENSE,sha256=2EmsBIyDCono4iVXNpv5_px9qt2b7hfPq1WuyGVMNP4,1361
12
+ staran-1.0.3.dist-info/METADATA,sha256=a8Ct1x3Sm_fqFJlBc7k4yzGzYtFUwFGEmfqNn_586XI,5528
13
+ staran-1.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ staran-1.0.3.dist-info/top_level.txt,sha256=NOUZtXSh5oSIEjHrC0lQ9WmoKtD010Q00dghWyag-Zs,7
15
+ staran-1.0.3.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.0'
42
- __author__ = 'StarAn'
43
- __description__ = 'Lightweight Python date utilities with smart format memory'