staran 0.1.0__tar.gz → 0.1.1__tar.gz
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-0.1.1/PKG-INFO +225 -0
- staran-0.1.1/README.md +200 -0
- {staran-0.1.0 → staran-0.1.1}/setup.cfg +0 -0
- {staran-0.1.0 → staran-0.1.1}/setup.py +2 -2
- staran-0.1.1/staran.egg-info/PKG-INFO +225 -0
- staran-0.1.1/staran.egg-info/SOURCES.txt +10 -0
- {staran-0.1.0 → staran-0.1.1}/staran.egg-info/dependency_links.txt +0 -0
- {staran-0.1.0 → staran-0.1.1}/staran.egg-info/requires.txt +0 -0
- {staran-0.1.0 → staran-0.1.1}/staran.egg-info/top_level.txt +0 -0
- staran-0.1.1/tools/__init__.py +20 -0
- staran-0.1.1/tools/date.py +207 -0
- staran-0.1.0/._LICENSE +0 -0
- staran-0.1.0/._PKG-INFO +0 -0
- staran-0.1.0/._README.md +0 -0
- staran-0.1.0/._setup.cfg +0 -0
- staran-0.1.0/._setup.py +0 -0
- staran-0.1.0/._staran.egg-info +0 -0
- staran-0.1.0/._tools +0 -0
- staran-0.1.0/PKG-INFO +0 -26
- staran-0.1.0/README.md +0 -1
- staran-0.1.0/staran.egg-info/._PKG-INFO +0 -0
- staran-0.1.0/staran.egg-info/._SOURCES.txt +0 -0
- staran-0.1.0/staran.egg-info/._dependency_links.txt +0 -0
- staran-0.1.0/staran.egg-info/._requires.txt +0 -0
- staran-0.1.0/staran.egg-info/._top_level.txt +0 -0
- staran-0.1.0/staran.egg-info/PKG-INFO +0 -26
- staran-0.1.0/staran.egg-info/SOURCES.txt +0 -18
- staran-0.1.0/tools/.___init__.py +0 -0
- staran-0.1.0/tools/._date +0 -0
- staran-0.1.0/tools/__init__.py +0 -70
- staran-0.1.0/tools/date/.___init__.py +0 -0
- staran-0.1.0/tools/date/._build_simple.py +0 -0
- staran-0.1.0/tools/date/._date.py +0 -0
- staran-0.1.0/tools/date/._platform_utils.py +0 -0
- staran-0.1.0/tools/date/__init__.py +0 -60
- staran-0.1.0/tools/date/build_simple.py +0 -109
- staran-0.1.0/tools/date/date.py +0 -857
- staran-0.1.0/tools/date/platform_utils.py +0 -189
- {staran-0.1.0 → staran-0.1.1}/LICENSE +0 -0
staran-0.1.1/PKG-INFO
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: staran
|
3
|
+
Version: 0.1.1
|
4
|
+
Summary: staran - 高性能Python工具库
|
5
|
+
Home-page: https://github.com/starlxa/staran
|
6
|
+
Author: StarAn
|
7
|
+
Author-email: starlxa@icloud.com
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Requires-Python: >=3.7
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENSE
|
13
|
+
Requires-Dist: numpy>=1.20
|
14
|
+
Requires-Dist: pandas
|
15
|
+
Dynamic: author
|
16
|
+
Dynamic: author-email
|
17
|
+
Dynamic: classifier
|
18
|
+
Dynamic: description
|
19
|
+
Dynamic: description-content-type
|
20
|
+
Dynamic: home-page
|
21
|
+
Dynamic: license-file
|
22
|
+
Dynamic: requires-dist
|
23
|
+
Dynamic: requires-python
|
24
|
+
Dynamic: summary
|
25
|
+
|
26
|
+
# Staran - 简化的Python日期工具库
|
27
|
+
|
28
|
+
## 📅 简洁高效的日期处理
|
29
|
+
|
30
|
+
Staran是一个基于Python标准库的简洁日期工具库,提供直观易用的API,无需复杂依赖。
|
31
|
+
|
32
|
+
## 🚀 快速开始
|
33
|
+
|
34
|
+
### 安装
|
35
|
+
```bash
|
36
|
+
pip install staran
|
37
|
+
```
|
38
|
+
|
39
|
+
### 基本使用
|
40
|
+
|
41
|
+
```python
|
42
|
+
from staran import Date, today, from_string
|
43
|
+
|
44
|
+
# 创建日期
|
45
|
+
today_date = today() # 今日
|
46
|
+
birthday = Date(1990, 5, 15) # 指定日期
|
47
|
+
event = from_string('20240615') # 从字符串
|
48
|
+
|
49
|
+
print(f"今天是: {today_date}")
|
50
|
+
print(f"生日: {birthday}")
|
51
|
+
print(f"活动日期: {event}")
|
52
|
+
```
|
53
|
+
|
54
|
+
## 📖 功能特性
|
55
|
+
|
56
|
+
### 1. 多种创建方式
|
57
|
+
```python
|
58
|
+
from tools.date import Date
|
59
|
+
|
60
|
+
# 方式1: 无参数 - 今日
|
61
|
+
today = Date()
|
62
|
+
|
63
|
+
# 方式2: 指定年月日
|
64
|
+
birthday = Date(1990, 5, 15)
|
65
|
+
|
66
|
+
# 方式3: 从字符串
|
67
|
+
event1 = Date('20240615') # YYYYMMDD
|
68
|
+
event2 = Date('2024-06-15') # 带分隔符
|
69
|
+
monthly = Date('202406') # YYYYMM (日期默认为1号)
|
70
|
+
|
71
|
+
# 方式4: 关键字参数
|
72
|
+
deadline = Date(year=2024, month=12, day=31)
|
73
|
+
```
|
74
|
+
|
75
|
+
### 2. 日期运算
|
76
|
+
```python
|
77
|
+
date = Date(2024, 6, 15)
|
78
|
+
|
79
|
+
# 加减天数
|
80
|
+
tomorrow = date.add_days(1)
|
81
|
+
last_week = date.add_days(-7)
|
82
|
+
|
83
|
+
# 加减月份
|
84
|
+
next_month = date.add_months(1)
|
85
|
+
last_year = date.add_months(-12)
|
86
|
+
|
87
|
+
# 计算日期差
|
88
|
+
diff_days = date.difference(Date(2024, 6, 1)) # 14天
|
89
|
+
```
|
90
|
+
|
91
|
+
### 3. 格式化和转换
|
92
|
+
```python
|
93
|
+
date = Date(2024, 6, 15)
|
94
|
+
|
95
|
+
# 格式化
|
96
|
+
print(date.format('%Y-%m-%d')) # 2024-06-15
|
97
|
+
print(date.format('%Y年%m月%d日')) # 2024年06月15日
|
98
|
+
|
99
|
+
# 转换
|
100
|
+
timestamp = date.to_timestamp() # 时间戳
|
101
|
+
dt_date = date.to_date() # datetime.date对象
|
102
|
+
dt_datetime = date.to_datetime() # datetime.datetime对象
|
103
|
+
```
|
104
|
+
|
105
|
+
### 4. 日期信息
|
106
|
+
```python
|
107
|
+
date = Date(2024, 6, 15)
|
108
|
+
|
109
|
+
# 基本信息
|
110
|
+
print(f"是否闰年: {date.is_leap_year()}") # False
|
111
|
+
print(f"星期几: {date.weekday()}") # 5 (Saturday)
|
112
|
+
print(f"当月天数: {date.days_in_month()}") # 30
|
113
|
+
print(f"当年天数: {date.days_in_year()}") # 365
|
114
|
+
```
|
115
|
+
|
116
|
+
### 5. 日期比较
|
117
|
+
```python
|
118
|
+
date1 = Date(2024, 6, 15)
|
119
|
+
date2 = Date(2024, 6, 16)
|
120
|
+
|
121
|
+
print(date1 < date2) # True
|
122
|
+
print(date1 == Date(2024, 6, 15)) # True
|
123
|
+
print(date1 >= date2) # False
|
124
|
+
```
|
125
|
+
|
126
|
+
## 🎯 设计理念
|
127
|
+
|
128
|
+
### 简洁性
|
129
|
+
- 基于Python标准库,无额外依赖
|
130
|
+
- 直观的API设计
|
131
|
+
- 清晰的错误消息
|
132
|
+
|
133
|
+
### 可靠性
|
134
|
+
- 完整的日期验证
|
135
|
+
- 处理边界情况(如闰年、月末)
|
136
|
+
- 标准的Python对象行为
|
137
|
+
|
138
|
+
### 实用性
|
139
|
+
- 支持常见的日期操作
|
140
|
+
- 灵活的创建方式
|
141
|
+
- 便捷的格式化选项
|
142
|
+
|
143
|
+
## 📁 项目结构
|
144
|
+
|
145
|
+
```
|
146
|
+
staran/
|
147
|
+
├── __init__.py # 主包入口
|
148
|
+
├── setup.py # 安装配置
|
149
|
+
├── LICENSE # MIT许可证
|
150
|
+
├── README.md # 本文档
|
151
|
+
├── test_simple.py # 功能测试
|
152
|
+
└── tools/ # 核心模块
|
153
|
+
├── __init__.py # 工具模块入口
|
154
|
+
└── date/ # 日期功能
|
155
|
+
├── __init__.py # 日期模块入口
|
156
|
+
└── date.py # Date类实现
|
157
|
+
```
|
158
|
+
|
159
|
+
## 🧪 测试
|
160
|
+
|
161
|
+
```bash
|
162
|
+
# 运行测试
|
163
|
+
python test_simple.py
|
164
|
+
```
|
165
|
+
|
166
|
+
预期输出:
|
167
|
+
```
|
168
|
+
📅 简化Date类测试
|
169
|
+
==============================
|
170
|
+
1. 基本创建:
|
171
|
+
今日: 2025-07-28
|
172
|
+
指定日期: 2024-06-15
|
173
|
+
从字符串: 2024-06-15
|
174
|
+
|
175
|
+
2. 日期操作:
|
176
|
+
明天: 2025-07-29
|
177
|
+
下月: 2025-08-28
|
178
|
+
|
179
|
+
3. 时间戳转换:
|
180
|
+
2024-06-15 时间戳: 1718380800.0
|
181
|
+
|
182
|
+
4. 格式化:
|
183
|
+
格式化: 2024年06月15日
|
184
|
+
|
185
|
+
5. 日期比较:
|
186
|
+
2024-06-15 < 2024-06-16: True
|
187
|
+
2024-06-15 == Date(2024, 6, 15): True
|
188
|
+
|
189
|
+
✅ 所有测试通过!
|
190
|
+
```
|
191
|
+
|
192
|
+
## 📋 API参考
|
193
|
+
|
194
|
+
### Date类
|
195
|
+
|
196
|
+
#### 构造方法
|
197
|
+
- `Date()` - 创建今日日期
|
198
|
+
- `Date(year, month, day)` - 指定年月日
|
199
|
+
- `Date(date_string)` - 从字符串创建
|
200
|
+
- `Date(year=y, month=m, day=d)` - 关键字参数
|
201
|
+
|
202
|
+
#### 核心方法
|
203
|
+
- `add_days(days)` - 增加/减少天数
|
204
|
+
- `add_months(months)` - 增加/减少月数
|
205
|
+
- `difference(other)` - 计算日期差
|
206
|
+
- `format(fmt)` - 格式化字符串
|
207
|
+
- `to_timestamp()` - 转换为时间戳
|
208
|
+
- `is_leap_year()` - 判断闰年
|
209
|
+
|
210
|
+
#### 便捷函数
|
211
|
+
- `today()` - 获取今日
|
212
|
+
- `from_string(s)` - 从字符串创建
|
213
|
+
- `from_timestamp(ts)` - 从时间戳创建
|
214
|
+
|
215
|
+
## 📄 许可证
|
216
|
+
|
217
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件
|
218
|
+
|
219
|
+
## 🤝 贡献
|
220
|
+
|
221
|
+
欢迎提交Issue和Pull Request!
|
222
|
+
|
223
|
+
---
|
224
|
+
|
225
|
+
**Staran** - 让日期处理变得简单 🌟
|
staran-0.1.1/README.md
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
# Staran - 简化的Python日期工具库
|
2
|
+
|
3
|
+
## 📅 简洁高效的日期处理
|
4
|
+
|
5
|
+
Staran是一个基于Python标准库的简洁日期工具库,提供直观易用的API,无需复杂依赖。
|
6
|
+
|
7
|
+
## 🚀 快速开始
|
8
|
+
|
9
|
+
### 安装
|
10
|
+
```bash
|
11
|
+
pip install staran
|
12
|
+
```
|
13
|
+
|
14
|
+
### 基本使用
|
15
|
+
|
16
|
+
```python
|
17
|
+
from staran import Date, today, from_string
|
18
|
+
|
19
|
+
# 创建日期
|
20
|
+
today_date = today() # 今日
|
21
|
+
birthday = Date(1990, 5, 15) # 指定日期
|
22
|
+
event = from_string('20240615') # 从字符串
|
23
|
+
|
24
|
+
print(f"今天是: {today_date}")
|
25
|
+
print(f"生日: {birthday}")
|
26
|
+
print(f"活动日期: {event}")
|
27
|
+
```
|
28
|
+
|
29
|
+
## 📖 功能特性
|
30
|
+
|
31
|
+
### 1. 多种创建方式
|
32
|
+
```python
|
33
|
+
from tools.date import Date
|
34
|
+
|
35
|
+
# 方式1: 无参数 - 今日
|
36
|
+
today = Date()
|
37
|
+
|
38
|
+
# 方式2: 指定年月日
|
39
|
+
birthday = Date(1990, 5, 15)
|
40
|
+
|
41
|
+
# 方式3: 从字符串
|
42
|
+
event1 = Date('20240615') # YYYYMMDD
|
43
|
+
event2 = Date('2024-06-15') # 带分隔符
|
44
|
+
monthly = Date('202406') # YYYYMM (日期默认为1号)
|
45
|
+
|
46
|
+
# 方式4: 关键字参数
|
47
|
+
deadline = Date(year=2024, month=12, day=31)
|
48
|
+
```
|
49
|
+
|
50
|
+
### 2. 日期运算
|
51
|
+
```python
|
52
|
+
date = Date(2024, 6, 15)
|
53
|
+
|
54
|
+
# 加减天数
|
55
|
+
tomorrow = date.add_days(1)
|
56
|
+
last_week = date.add_days(-7)
|
57
|
+
|
58
|
+
# 加减月份
|
59
|
+
next_month = date.add_months(1)
|
60
|
+
last_year = date.add_months(-12)
|
61
|
+
|
62
|
+
# 计算日期差
|
63
|
+
diff_days = date.difference(Date(2024, 6, 1)) # 14天
|
64
|
+
```
|
65
|
+
|
66
|
+
### 3. 格式化和转换
|
67
|
+
```python
|
68
|
+
date = Date(2024, 6, 15)
|
69
|
+
|
70
|
+
# 格式化
|
71
|
+
print(date.format('%Y-%m-%d')) # 2024-06-15
|
72
|
+
print(date.format('%Y年%m月%d日')) # 2024年06月15日
|
73
|
+
|
74
|
+
# 转换
|
75
|
+
timestamp = date.to_timestamp() # 时间戳
|
76
|
+
dt_date = date.to_date() # datetime.date对象
|
77
|
+
dt_datetime = date.to_datetime() # datetime.datetime对象
|
78
|
+
```
|
79
|
+
|
80
|
+
### 4. 日期信息
|
81
|
+
```python
|
82
|
+
date = Date(2024, 6, 15)
|
83
|
+
|
84
|
+
# 基本信息
|
85
|
+
print(f"是否闰年: {date.is_leap_year()}") # False
|
86
|
+
print(f"星期几: {date.weekday()}") # 5 (Saturday)
|
87
|
+
print(f"当月天数: {date.days_in_month()}") # 30
|
88
|
+
print(f"当年天数: {date.days_in_year()}") # 365
|
89
|
+
```
|
90
|
+
|
91
|
+
### 5. 日期比较
|
92
|
+
```python
|
93
|
+
date1 = Date(2024, 6, 15)
|
94
|
+
date2 = Date(2024, 6, 16)
|
95
|
+
|
96
|
+
print(date1 < date2) # True
|
97
|
+
print(date1 == Date(2024, 6, 15)) # True
|
98
|
+
print(date1 >= date2) # False
|
99
|
+
```
|
100
|
+
|
101
|
+
## 🎯 设计理念
|
102
|
+
|
103
|
+
### 简洁性
|
104
|
+
- 基于Python标准库,无额外依赖
|
105
|
+
- 直观的API设计
|
106
|
+
- 清晰的错误消息
|
107
|
+
|
108
|
+
### 可靠性
|
109
|
+
- 完整的日期验证
|
110
|
+
- 处理边界情况(如闰年、月末)
|
111
|
+
- 标准的Python对象行为
|
112
|
+
|
113
|
+
### 实用性
|
114
|
+
- 支持常见的日期操作
|
115
|
+
- 灵活的创建方式
|
116
|
+
- 便捷的格式化选项
|
117
|
+
|
118
|
+
## 📁 项目结构
|
119
|
+
|
120
|
+
```
|
121
|
+
staran/
|
122
|
+
├── __init__.py # 主包入口
|
123
|
+
├── setup.py # 安装配置
|
124
|
+
├── LICENSE # MIT许可证
|
125
|
+
├── README.md # 本文档
|
126
|
+
├── test_simple.py # 功能测试
|
127
|
+
└── tools/ # 核心模块
|
128
|
+
├── __init__.py # 工具模块入口
|
129
|
+
└── date/ # 日期功能
|
130
|
+
├── __init__.py # 日期模块入口
|
131
|
+
└── date.py # Date类实现
|
132
|
+
```
|
133
|
+
|
134
|
+
## 🧪 测试
|
135
|
+
|
136
|
+
```bash
|
137
|
+
# 运行测试
|
138
|
+
python test_simple.py
|
139
|
+
```
|
140
|
+
|
141
|
+
预期输出:
|
142
|
+
```
|
143
|
+
📅 简化Date类测试
|
144
|
+
==============================
|
145
|
+
1. 基本创建:
|
146
|
+
今日: 2025-07-28
|
147
|
+
指定日期: 2024-06-15
|
148
|
+
从字符串: 2024-06-15
|
149
|
+
|
150
|
+
2. 日期操作:
|
151
|
+
明天: 2025-07-29
|
152
|
+
下月: 2025-08-28
|
153
|
+
|
154
|
+
3. 时间戳转换:
|
155
|
+
2024-06-15 时间戳: 1718380800.0
|
156
|
+
|
157
|
+
4. 格式化:
|
158
|
+
格式化: 2024年06月15日
|
159
|
+
|
160
|
+
5. 日期比较:
|
161
|
+
2024-06-15 < 2024-06-16: True
|
162
|
+
2024-06-15 == Date(2024, 6, 15): True
|
163
|
+
|
164
|
+
✅ 所有测试通过!
|
165
|
+
```
|
166
|
+
|
167
|
+
## 📋 API参考
|
168
|
+
|
169
|
+
### Date类
|
170
|
+
|
171
|
+
#### 构造方法
|
172
|
+
- `Date()` - 创建今日日期
|
173
|
+
- `Date(year, month, day)` - 指定年月日
|
174
|
+
- `Date(date_string)` - 从字符串创建
|
175
|
+
- `Date(year=y, month=m, day=d)` - 关键字参数
|
176
|
+
|
177
|
+
#### 核心方法
|
178
|
+
- `add_days(days)` - 增加/减少天数
|
179
|
+
- `add_months(months)` - 增加/减少月数
|
180
|
+
- `difference(other)` - 计算日期差
|
181
|
+
- `format(fmt)` - 格式化字符串
|
182
|
+
- `to_timestamp()` - 转换为时间戳
|
183
|
+
- `is_leap_year()` - 判断闰年
|
184
|
+
|
185
|
+
#### 便捷函数
|
186
|
+
- `today()` - 获取今日
|
187
|
+
- `from_string(s)` - 从字符串创建
|
188
|
+
- `from_timestamp(ts)` - 从时间戳创建
|
189
|
+
|
190
|
+
## 📄 许可证
|
191
|
+
|
192
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件
|
193
|
+
|
194
|
+
## 🤝 贡献
|
195
|
+
|
196
|
+
欢迎提交Issue和Pull Request!
|
197
|
+
|
198
|
+
---
|
199
|
+
|
200
|
+
**Staran** - 让日期处理变得简单 🌟
|
File without changes
|
@@ -2,8 +2,8 @@ from setuptools import setup, find_packages
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name='staran',
|
5
|
-
version='0.1.
|
6
|
-
description='
|
5
|
+
version='0.1.1',
|
6
|
+
description='staran - 高性能Python工具库',
|
7
7
|
long_description=open('README.md', encoding='utf-8').read(),
|
8
8
|
long_description_content_type='text/markdown',
|
9
9
|
author='StarAn',
|
@@ -0,0 +1,225 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: staran
|
3
|
+
Version: 0.1.1
|
4
|
+
Summary: staran - 高性能Python工具库
|
5
|
+
Home-page: https://github.com/starlxa/staran
|
6
|
+
Author: StarAn
|
7
|
+
Author-email: starlxa@icloud.com
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Requires-Python: >=3.7
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENSE
|
13
|
+
Requires-Dist: numpy>=1.20
|
14
|
+
Requires-Dist: pandas
|
15
|
+
Dynamic: author
|
16
|
+
Dynamic: author-email
|
17
|
+
Dynamic: classifier
|
18
|
+
Dynamic: description
|
19
|
+
Dynamic: description-content-type
|
20
|
+
Dynamic: home-page
|
21
|
+
Dynamic: license-file
|
22
|
+
Dynamic: requires-dist
|
23
|
+
Dynamic: requires-python
|
24
|
+
Dynamic: summary
|
25
|
+
|
26
|
+
# Staran - 简化的Python日期工具库
|
27
|
+
|
28
|
+
## 📅 简洁高效的日期处理
|
29
|
+
|
30
|
+
Staran是一个基于Python标准库的简洁日期工具库,提供直观易用的API,无需复杂依赖。
|
31
|
+
|
32
|
+
## 🚀 快速开始
|
33
|
+
|
34
|
+
### 安装
|
35
|
+
```bash
|
36
|
+
pip install staran
|
37
|
+
```
|
38
|
+
|
39
|
+
### 基本使用
|
40
|
+
|
41
|
+
```python
|
42
|
+
from staran import Date, today, from_string
|
43
|
+
|
44
|
+
# 创建日期
|
45
|
+
today_date = today() # 今日
|
46
|
+
birthday = Date(1990, 5, 15) # 指定日期
|
47
|
+
event = from_string('20240615') # 从字符串
|
48
|
+
|
49
|
+
print(f"今天是: {today_date}")
|
50
|
+
print(f"生日: {birthday}")
|
51
|
+
print(f"活动日期: {event}")
|
52
|
+
```
|
53
|
+
|
54
|
+
## 📖 功能特性
|
55
|
+
|
56
|
+
### 1. 多种创建方式
|
57
|
+
```python
|
58
|
+
from tools.date import Date
|
59
|
+
|
60
|
+
# 方式1: 无参数 - 今日
|
61
|
+
today = Date()
|
62
|
+
|
63
|
+
# 方式2: 指定年月日
|
64
|
+
birthday = Date(1990, 5, 15)
|
65
|
+
|
66
|
+
# 方式3: 从字符串
|
67
|
+
event1 = Date('20240615') # YYYYMMDD
|
68
|
+
event2 = Date('2024-06-15') # 带分隔符
|
69
|
+
monthly = Date('202406') # YYYYMM (日期默认为1号)
|
70
|
+
|
71
|
+
# 方式4: 关键字参数
|
72
|
+
deadline = Date(year=2024, month=12, day=31)
|
73
|
+
```
|
74
|
+
|
75
|
+
### 2. 日期运算
|
76
|
+
```python
|
77
|
+
date = Date(2024, 6, 15)
|
78
|
+
|
79
|
+
# 加减天数
|
80
|
+
tomorrow = date.add_days(1)
|
81
|
+
last_week = date.add_days(-7)
|
82
|
+
|
83
|
+
# 加减月份
|
84
|
+
next_month = date.add_months(1)
|
85
|
+
last_year = date.add_months(-12)
|
86
|
+
|
87
|
+
# 计算日期差
|
88
|
+
diff_days = date.difference(Date(2024, 6, 1)) # 14天
|
89
|
+
```
|
90
|
+
|
91
|
+
### 3. 格式化和转换
|
92
|
+
```python
|
93
|
+
date = Date(2024, 6, 15)
|
94
|
+
|
95
|
+
# 格式化
|
96
|
+
print(date.format('%Y-%m-%d')) # 2024-06-15
|
97
|
+
print(date.format('%Y年%m月%d日')) # 2024年06月15日
|
98
|
+
|
99
|
+
# 转换
|
100
|
+
timestamp = date.to_timestamp() # 时间戳
|
101
|
+
dt_date = date.to_date() # datetime.date对象
|
102
|
+
dt_datetime = date.to_datetime() # datetime.datetime对象
|
103
|
+
```
|
104
|
+
|
105
|
+
### 4. 日期信息
|
106
|
+
```python
|
107
|
+
date = Date(2024, 6, 15)
|
108
|
+
|
109
|
+
# 基本信息
|
110
|
+
print(f"是否闰年: {date.is_leap_year()}") # False
|
111
|
+
print(f"星期几: {date.weekday()}") # 5 (Saturday)
|
112
|
+
print(f"当月天数: {date.days_in_month()}") # 30
|
113
|
+
print(f"当年天数: {date.days_in_year()}") # 365
|
114
|
+
```
|
115
|
+
|
116
|
+
### 5. 日期比较
|
117
|
+
```python
|
118
|
+
date1 = Date(2024, 6, 15)
|
119
|
+
date2 = Date(2024, 6, 16)
|
120
|
+
|
121
|
+
print(date1 < date2) # True
|
122
|
+
print(date1 == Date(2024, 6, 15)) # True
|
123
|
+
print(date1 >= date2) # False
|
124
|
+
```
|
125
|
+
|
126
|
+
## 🎯 设计理念
|
127
|
+
|
128
|
+
### 简洁性
|
129
|
+
- 基于Python标准库,无额外依赖
|
130
|
+
- 直观的API设计
|
131
|
+
- 清晰的错误消息
|
132
|
+
|
133
|
+
### 可靠性
|
134
|
+
- 完整的日期验证
|
135
|
+
- 处理边界情况(如闰年、月末)
|
136
|
+
- 标准的Python对象行为
|
137
|
+
|
138
|
+
### 实用性
|
139
|
+
- 支持常见的日期操作
|
140
|
+
- 灵活的创建方式
|
141
|
+
- 便捷的格式化选项
|
142
|
+
|
143
|
+
## 📁 项目结构
|
144
|
+
|
145
|
+
```
|
146
|
+
staran/
|
147
|
+
├── __init__.py # 主包入口
|
148
|
+
├── setup.py # 安装配置
|
149
|
+
├── LICENSE # MIT许可证
|
150
|
+
├── README.md # 本文档
|
151
|
+
├── test_simple.py # 功能测试
|
152
|
+
└── tools/ # 核心模块
|
153
|
+
├── __init__.py # 工具模块入口
|
154
|
+
└── date/ # 日期功能
|
155
|
+
├── __init__.py # 日期模块入口
|
156
|
+
└── date.py # Date类实现
|
157
|
+
```
|
158
|
+
|
159
|
+
## 🧪 测试
|
160
|
+
|
161
|
+
```bash
|
162
|
+
# 运行测试
|
163
|
+
python test_simple.py
|
164
|
+
```
|
165
|
+
|
166
|
+
预期输出:
|
167
|
+
```
|
168
|
+
📅 简化Date类测试
|
169
|
+
==============================
|
170
|
+
1. 基本创建:
|
171
|
+
今日: 2025-07-28
|
172
|
+
指定日期: 2024-06-15
|
173
|
+
从字符串: 2024-06-15
|
174
|
+
|
175
|
+
2. 日期操作:
|
176
|
+
明天: 2025-07-29
|
177
|
+
下月: 2025-08-28
|
178
|
+
|
179
|
+
3. 时间戳转换:
|
180
|
+
2024-06-15 时间戳: 1718380800.0
|
181
|
+
|
182
|
+
4. 格式化:
|
183
|
+
格式化: 2024年06月15日
|
184
|
+
|
185
|
+
5. 日期比较:
|
186
|
+
2024-06-15 < 2024-06-16: True
|
187
|
+
2024-06-15 == Date(2024, 6, 15): True
|
188
|
+
|
189
|
+
✅ 所有测试通过!
|
190
|
+
```
|
191
|
+
|
192
|
+
## 📋 API参考
|
193
|
+
|
194
|
+
### Date类
|
195
|
+
|
196
|
+
#### 构造方法
|
197
|
+
- `Date()` - 创建今日日期
|
198
|
+
- `Date(year, month, day)` - 指定年月日
|
199
|
+
- `Date(date_string)` - 从字符串创建
|
200
|
+
- `Date(year=y, month=m, day=d)` - 关键字参数
|
201
|
+
|
202
|
+
#### 核心方法
|
203
|
+
- `add_days(days)` - 增加/减少天数
|
204
|
+
- `add_months(months)` - 增加/减少月数
|
205
|
+
- `difference(other)` - 计算日期差
|
206
|
+
- `format(fmt)` - 格式化字符串
|
207
|
+
- `to_timestamp()` - 转换为时间戳
|
208
|
+
- `is_leap_year()` - 判断闰年
|
209
|
+
|
210
|
+
#### 便捷函数
|
211
|
+
- `today()` - 获取今日
|
212
|
+
- `from_string(s)` - 从字符串创建
|
213
|
+
- `from_timestamp(ts)` - 从时间戳创建
|
214
|
+
|
215
|
+
## 📄 许可证
|
216
|
+
|
217
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件
|
218
|
+
|
219
|
+
## 🤝 贡献
|
220
|
+
|
221
|
+
欢迎提交Issue和Pull Request!
|
222
|
+
|
223
|
+
---
|
224
|
+
|
225
|
+
**Staran** - 让日期处理变得简单 🌟
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
"""
|
5
|
+
Staran Tools - 简化的工具集合
|
6
|
+
提供日期处理等实用功能
|
7
|
+
"""
|
8
|
+
|
9
|
+
# 导入date模块的主要类和函数
|
10
|
+
from .date import Date
|
11
|
+
|
12
|
+
# 主要导出
|
13
|
+
__all__ = [
|
14
|
+
'Date'
|
15
|
+
]
|
16
|
+
|
17
|
+
# 模块信息
|
18
|
+
__version__ = '1.0.0'
|
19
|
+
__author__ = 'Staran Team'
|
20
|
+
__description__ = 'Staran simple tools collection'
|