qrpa 1.1.33__py3-none-any.whl → 1.1.35__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.
Potentially problematic release.
This version of qrpa might be problematic. Click here for more details.
- qrpa/RateLimitedSender.py +45 -45
- qrpa/__init__.py +31 -31
- qrpa/db_migrator.py +600 -600
- qrpa/feishu_bot_app.py +267 -267
- qrpa/fun_base.py +339 -339
- qrpa/fun_excel.py +3059 -3059
- qrpa/fun_file.py +318 -318
- qrpa/fun_web.py +258 -258
- qrpa/fun_win.py +198 -198
- qrpa/mysql_module/new_product_analysis_model.py +488 -0
- qrpa/mysql_module/shein_ledger_model.py +468 -468
- qrpa/mysql_module/shein_product_model.py +484 -484
- qrpa/mysql_module/shein_return_order_model.py +569 -569
- qrpa/mysql_module/shein_store_model.py +594 -0
- qrpa/shein_daily_report_model.py +375 -375
- qrpa/shein_excel.py +3125 -3125
- qrpa/shein_lib.py +3932 -3607
- qrpa/shein_mysql.py +22 -0
- qrpa/shein_sqlite.py +153 -153
- qrpa/shein_ziniao.py +529 -529
- qrpa/temu_chrome.py +56 -56
- qrpa/temu_excel.py +139 -139
- qrpa/temu_lib.py +154 -154
- qrpa/time_utils.py +882 -882
- qrpa/time_utils_example.py +243 -243
- qrpa/wxwork.py +318 -318
- {qrpa-1.1.33.dist-info → qrpa-1.1.35.dist-info}/METADATA +1 -1
- qrpa-1.1.35.dist-info/RECORD +33 -0
- qrpa-1.1.33.dist-info/RECORD +0 -31
- {qrpa-1.1.33.dist-info → qrpa-1.1.35.dist-info}/WHEEL +0 -0
- {qrpa-1.1.33.dist-info → qrpa-1.1.35.dist-info}/top_level.txt +0 -0
qrpa/time_utils_example.py
CHANGED
|
@@ -1,243 +1,243 @@
|
|
|
1
|
-
"""
|
|
2
|
-
时间工具模块使用示例
|
|
3
|
-
展示如何使用 time_utils.py 中的各种时间相关函数
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from time_utils import TimeUtils, today_date, get_yesterday, get_current_year
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def example_basic_usage():
|
|
10
|
-
"""基础使用示例"""
|
|
11
|
-
print("=== 基础使用示例 ===")
|
|
12
|
-
|
|
13
|
-
# 获取当前时间信息
|
|
14
|
-
print(f"当前日期: {today_date()}")
|
|
15
|
-
print(f"昨天: {get_yesterday()}")
|
|
16
|
-
print(f"当前年份: {get_current_year()}")
|
|
17
|
-
print(f"当前周数: {TimeUtils.get_week_num()}")
|
|
18
|
-
print(f"当前时间段: {TimeUtils.get_period()}")
|
|
19
|
-
print(f"中文星期: {TimeUtils.get_chinese_weekday(today_date())}")
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def example_date_ranges():
|
|
23
|
-
"""日期范围计算示例"""
|
|
24
|
-
print("\n=== 日期范围计算示例 ===")
|
|
25
|
-
|
|
26
|
-
# 获取过去7天的日期范围
|
|
27
|
-
start, end = TimeUtils.get_past_7_days_range()
|
|
28
|
-
print(f"过去7天范围: {start} 到 {end}")
|
|
29
|
-
|
|
30
|
-
# 获取过去7天的日期列表
|
|
31
|
-
dates = TimeUtils.get_past_7_days_list()
|
|
32
|
-
print(f"过去7天列表: {dates}")
|
|
33
|
-
|
|
34
|
-
# 获取指定日期范围
|
|
35
|
-
date_list = TimeUtils.date_range('2025-01-01', '2025-01-05')
|
|
36
|
-
print(f"2025年1月1-5日: {date_list}")
|
|
37
|
-
|
|
38
|
-
# 获取上个月范围
|
|
39
|
-
last_month_start, last_month_end = TimeUtils.get_last_month_range()
|
|
40
|
-
print(f"上个月范围: {last_month_start} 到 {last_month_end}")
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def example_timestamp_conversion():
|
|
44
|
-
"""时间戳转换示例"""
|
|
45
|
-
print("\n=== 时间戳转换示例 ===")
|
|
46
|
-
|
|
47
|
-
from datetime import datetime
|
|
48
|
-
|
|
49
|
-
# 获取当前时间戳
|
|
50
|
-
current_ts = int(datetime.now().timestamp() * 1000)
|
|
51
|
-
print(f"当前时间戳: {current_ts}")
|
|
52
|
-
|
|
53
|
-
# 时间戳转字符串
|
|
54
|
-
time_str = TimeUtils.convert_timestamp_to_str(current_ts)
|
|
55
|
-
print(f"时间戳转字符串: {time_str}")
|
|
56
|
-
|
|
57
|
-
# 时间戳转日期
|
|
58
|
-
date_str = TimeUtils.convert_timestamp_to_date(current_ts)
|
|
59
|
-
print(f"时间戳转日期: {date_str}")
|
|
60
|
-
|
|
61
|
-
# 获取指定日期的开始和结束时间戳
|
|
62
|
-
start_ts = TimeUtils.get_start_timestamps('2025-01-01')
|
|
63
|
-
end_ts = TimeUtils.get_end_timestamps('2025-01-01')
|
|
64
|
-
print(f"2025-01-01 开始时间戳: {start_ts}")
|
|
65
|
-
print(f"2025-01-01 结束时间戳: {end_ts}")
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def example_date_comparison():
|
|
69
|
-
"""日期比较示例"""
|
|
70
|
-
print("\n=== 日期比较示例 ===")
|
|
71
|
-
|
|
72
|
-
# 判断日期是否大于等于今天
|
|
73
|
-
is_future = TimeUtils.is_date_greater_or_equal('2025-12-31')
|
|
74
|
-
print(f"2025-12-31 是否大于等于今天: {is_future}")
|
|
75
|
-
|
|
76
|
-
# 判断是否是昨天
|
|
77
|
-
is_yesterday = TimeUtils.is_yesterday_date('2025-01-01')
|
|
78
|
-
print(f"2025-01-01 是否是昨天: {is_yesterday}")
|
|
79
|
-
|
|
80
|
-
# 判断时间是否在指定月份
|
|
81
|
-
in_month = TimeUtils.is_in_month('2025-01-15', 1)
|
|
82
|
-
print(f"2025-01-15 是否在1月: {in_month}")
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def example_date_formatting():
|
|
86
|
-
"""日期格式化示例"""
|
|
87
|
-
print("\n=== 日期格式化示例 ===")
|
|
88
|
-
|
|
89
|
-
# 日期格式转换
|
|
90
|
-
date_with_slash = TimeUtils.date_trans('2025-01-01')
|
|
91
|
-
print(f"2025-01-01 转换为: {date_with_slash}")
|
|
92
|
-
|
|
93
|
-
# 跨平台格式化
|
|
94
|
-
cross_platform = TimeUtils.format_date_cross_platform('2025-01-01')
|
|
95
|
-
print(f"跨平台格式化: {cross_platform}")
|
|
96
|
-
|
|
97
|
-
# 时间字符串转日期
|
|
98
|
-
date_only = TimeUtils.convert_datetime_to_date('2025-01-01 12:30:45')
|
|
99
|
-
print(f"时间字符串转日期: {date_only}")
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def example_advanced_usage():
|
|
103
|
-
"""高级使用示例"""
|
|
104
|
-
print("\n=== 高级使用示例 ===")
|
|
105
|
-
|
|
106
|
-
# 获取过去第n天的日期
|
|
107
|
-
past_5th_day = TimeUtils.get_past_nth_day(5)
|
|
108
|
-
print(f"过去第5天: {past_5th_day}")
|
|
109
|
-
|
|
110
|
-
# 获取过去n天的日期列表
|
|
111
|
-
past_10_days = TimeUtils.get_past_n_days_list(10)
|
|
112
|
-
print(f"过去10天列表: {past_10_days}")
|
|
113
|
-
|
|
114
|
-
# 获取从本月第一天到昨天的日期列表
|
|
115
|
-
month_dates = TimeUtils.get_dates_from_first_of_month_to_yesterday()
|
|
116
|
-
print(f"本月到昨天的日期: {month_dates}")
|
|
117
|
-
|
|
118
|
-
# 获取上个月的时间范围(字符串格式)
|
|
119
|
-
last_month_start_str, last_month_end_str = TimeUtils.get_last_month_range_time_str()
|
|
120
|
-
print(f"上个月时间范围: {last_month_start_str} 到 {last_month_end_str}")
|
|
121
|
-
|
|
122
|
-
# 获取上个月的时间范围(时间戳格式)
|
|
123
|
-
last_month_start_ts, last_month_end_ts = TimeUtils.get_last_month_range_time()
|
|
124
|
-
print(f"上个月时间戳范围: {last_month_start_ts} 到 {last_month_end_ts}")
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def example_file_time():
|
|
128
|
-
"""文件时间相关示例"""
|
|
129
|
-
print("\n=== 文件时间相关示例 ===")
|
|
130
|
-
|
|
131
|
-
import os
|
|
132
|
-
|
|
133
|
-
# 创建一个临时文件用于测试
|
|
134
|
-
test_file = "test_file.txt"
|
|
135
|
-
with open(test_file, 'w') as f:
|
|
136
|
-
f.write("test content")
|
|
137
|
-
|
|
138
|
-
try:
|
|
139
|
-
# 获取文件修改时间
|
|
140
|
-
file_mtime = TimeUtils.get_file_mtime(test_file)
|
|
141
|
-
print(f"文件修改时间: {file_mtime}")
|
|
142
|
-
|
|
143
|
-
# 获取文件修改时间(datetime对象)
|
|
144
|
-
file_mtime_dt = TimeUtils.get_file_mtime(test_file, to_str=False)
|
|
145
|
-
print(f"文件修改时间(datetime): {file_mtime_dt}")
|
|
146
|
-
|
|
147
|
-
finally:
|
|
148
|
-
# 清理测试文件
|
|
149
|
-
if os.path.exists(test_file):
|
|
150
|
-
os.remove(test_file)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
def example_weekday_functions():
|
|
154
|
-
"""星期相关函数示例"""
|
|
155
|
-
print("\n=== 星期相关函数示例 ===")
|
|
156
|
-
|
|
157
|
-
# 获取中文星期
|
|
158
|
-
weekday_cn = TimeUtils.get_chinese_weekday('2025-01-01')
|
|
159
|
-
print(f"2025-01-01 的中文星期: {weekday_cn}")
|
|
160
|
-
|
|
161
|
-
# 获取简短星期名称
|
|
162
|
-
weekday_short = TimeUtils.get_weekday_name('2025-01-01')
|
|
163
|
-
print(f"2025-01-01 的简短星期: {weekday_short}")
|
|
164
|
-
|
|
165
|
-
# 获取当前周数
|
|
166
|
-
week_num = TimeUtils.get_week_num()
|
|
167
|
-
print(f"当前是第 {week_num} 周")
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def example_period_functions():
|
|
171
|
-
"""时间段相关函数示例"""
|
|
172
|
-
print("\n=== 时间段相关函数示例 ===")
|
|
173
|
-
|
|
174
|
-
# 获取当前时间段(中文)
|
|
175
|
-
period_cn = TimeUtils.get_period()
|
|
176
|
-
print(f"当前时间段(中文): {period_cn}")
|
|
177
|
-
|
|
178
|
-
# 获取当前时间段(英文)
|
|
179
|
-
period_en = TimeUtils.get_period2()
|
|
180
|
-
print(f"当前时间段(英文): {period_en}")
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
def example_year_month_functions():
|
|
184
|
-
"""年月相关函数示例"""
|
|
185
|
-
print("\n=== 年月相关函数示例 ===")
|
|
186
|
-
|
|
187
|
-
# 获取当前年份
|
|
188
|
-
current_year = TimeUtils.get_current_year()
|
|
189
|
-
print(f"当前年份: {current_year}")
|
|
190
|
-
|
|
191
|
-
# 获取当前月份
|
|
192
|
-
current_month = TimeUtils.get_current_month()
|
|
193
|
-
print(f"当前月份: {current_month}")
|
|
194
|
-
|
|
195
|
-
# 获取上个月
|
|
196
|
-
last_month = TimeUtils.get_last_month()
|
|
197
|
-
print(f"上个月: {last_month}")
|
|
198
|
-
|
|
199
|
-
# 获取当前年份范围
|
|
200
|
-
year_start, year_end = TimeUtils.get_current_year_range()
|
|
201
|
-
print(f"当前年份范围: {year_start} 到 {year_end}")
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
def example_relative_dates():
|
|
205
|
-
"""相对日期函数示例"""
|
|
206
|
-
print("\n=== 相对日期函数示例 ===")
|
|
207
|
-
|
|
208
|
-
# 获取昨天
|
|
209
|
-
yesterday = TimeUtils.get_yesterday()
|
|
210
|
-
print(f"昨天: {yesterday}")
|
|
211
|
-
|
|
212
|
-
# 获取前天
|
|
213
|
-
before_yesterday = TimeUtils.before_yesterday()
|
|
214
|
-
print(f"前天: {before_yesterday}")
|
|
215
|
-
|
|
216
|
-
# 获取明天
|
|
217
|
-
tomorrow = TimeUtils.tomorrow_date()
|
|
218
|
-
print(f"明天: {tomorrow}")
|
|
219
|
-
|
|
220
|
-
# 基于指定日期获取昨天
|
|
221
|
-
yesterday_from_date = TimeUtils.get_yesterday('20250101')
|
|
222
|
-
print(f"基于2025-01-01的昨天: {yesterday_from_date}")
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if __name__ == "__main__":
|
|
226
|
-
"""运行所有示例"""
|
|
227
|
-
print("时间工具模块使用示例")
|
|
228
|
-
print("=" * 50)
|
|
229
|
-
|
|
230
|
-
example_basic_usage()
|
|
231
|
-
example_date_ranges()
|
|
232
|
-
example_timestamp_conversion()
|
|
233
|
-
example_date_comparison()
|
|
234
|
-
example_date_formatting()
|
|
235
|
-
example_advanced_usage()
|
|
236
|
-
example_file_time()
|
|
237
|
-
example_weekday_functions()
|
|
238
|
-
example_period_functions()
|
|
239
|
-
example_year_month_functions()
|
|
240
|
-
example_relative_dates()
|
|
241
|
-
|
|
242
|
-
print("\n" + "=" * 50)
|
|
243
|
-
print("所有示例运行完成!")
|
|
1
|
+
"""
|
|
2
|
+
时间工具模块使用示例
|
|
3
|
+
展示如何使用 time_utils.py 中的各种时间相关函数
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from time_utils import TimeUtils, today_date, get_yesterday, get_current_year
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def example_basic_usage():
|
|
10
|
+
"""基础使用示例"""
|
|
11
|
+
print("=== 基础使用示例 ===")
|
|
12
|
+
|
|
13
|
+
# 获取当前时间信息
|
|
14
|
+
print(f"当前日期: {today_date()}")
|
|
15
|
+
print(f"昨天: {get_yesterday()}")
|
|
16
|
+
print(f"当前年份: {get_current_year()}")
|
|
17
|
+
print(f"当前周数: {TimeUtils.get_week_num()}")
|
|
18
|
+
print(f"当前时间段: {TimeUtils.get_period()}")
|
|
19
|
+
print(f"中文星期: {TimeUtils.get_chinese_weekday(today_date())}")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def example_date_ranges():
|
|
23
|
+
"""日期范围计算示例"""
|
|
24
|
+
print("\n=== 日期范围计算示例 ===")
|
|
25
|
+
|
|
26
|
+
# 获取过去7天的日期范围
|
|
27
|
+
start, end = TimeUtils.get_past_7_days_range()
|
|
28
|
+
print(f"过去7天范围: {start} 到 {end}")
|
|
29
|
+
|
|
30
|
+
# 获取过去7天的日期列表
|
|
31
|
+
dates = TimeUtils.get_past_7_days_list()
|
|
32
|
+
print(f"过去7天列表: {dates}")
|
|
33
|
+
|
|
34
|
+
# 获取指定日期范围
|
|
35
|
+
date_list = TimeUtils.date_range('2025-01-01', '2025-01-05')
|
|
36
|
+
print(f"2025年1月1-5日: {date_list}")
|
|
37
|
+
|
|
38
|
+
# 获取上个月范围
|
|
39
|
+
last_month_start, last_month_end = TimeUtils.get_last_month_range()
|
|
40
|
+
print(f"上个月范围: {last_month_start} 到 {last_month_end}")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def example_timestamp_conversion():
|
|
44
|
+
"""时间戳转换示例"""
|
|
45
|
+
print("\n=== 时间戳转换示例 ===")
|
|
46
|
+
|
|
47
|
+
from datetime import datetime
|
|
48
|
+
|
|
49
|
+
# 获取当前时间戳
|
|
50
|
+
current_ts = int(datetime.now().timestamp() * 1000)
|
|
51
|
+
print(f"当前时间戳: {current_ts}")
|
|
52
|
+
|
|
53
|
+
# 时间戳转字符串
|
|
54
|
+
time_str = TimeUtils.convert_timestamp_to_str(current_ts)
|
|
55
|
+
print(f"时间戳转字符串: {time_str}")
|
|
56
|
+
|
|
57
|
+
# 时间戳转日期
|
|
58
|
+
date_str = TimeUtils.convert_timestamp_to_date(current_ts)
|
|
59
|
+
print(f"时间戳转日期: {date_str}")
|
|
60
|
+
|
|
61
|
+
# 获取指定日期的开始和结束时间戳
|
|
62
|
+
start_ts = TimeUtils.get_start_timestamps('2025-01-01')
|
|
63
|
+
end_ts = TimeUtils.get_end_timestamps('2025-01-01')
|
|
64
|
+
print(f"2025-01-01 开始时间戳: {start_ts}")
|
|
65
|
+
print(f"2025-01-01 结束时间戳: {end_ts}")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def example_date_comparison():
|
|
69
|
+
"""日期比较示例"""
|
|
70
|
+
print("\n=== 日期比较示例 ===")
|
|
71
|
+
|
|
72
|
+
# 判断日期是否大于等于今天
|
|
73
|
+
is_future = TimeUtils.is_date_greater_or_equal('2025-12-31')
|
|
74
|
+
print(f"2025-12-31 是否大于等于今天: {is_future}")
|
|
75
|
+
|
|
76
|
+
# 判断是否是昨天
|
|
77
|
+
is_yesterday = TimeUtils.is_yesterday_date('2025-01-01')
|
|
78
|
+
print(f"2025-01-01 是否是昨天: {is_yesterday}")
|
|
79
|
+
|
|
80
|
+
# 判断时间是否在指定月份
|
|
81
|
+
in_month = TimeUtils.is_in_month('2025-01-15', 1)
|
|
82
|
+
print(f"2025-01-15 是否在1月: {in_month}")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def example_date_formatting():
|
|
86
|
+
"""日期格式化示例"""
|
|
87
|
+
print("\n=== 日期格式化示例 ===")
|
|
88
|
+
|
|
89
|
+
# 日期格式转换
|
|
90
|
+
date_with_slash = TimeUtils.date_trans('2025-01-01')
|
|
91
|
+
print(f"2025-01-01 转换为: {date_with_slash}")
|
|
92
|
+
|
|
93
|
+
# 跨平台格式化
|
|
94
|
+
cross_platform = TimeUtils.format_date_cross_platform('2025-01-01')
|
|
95
|
+
print(f"跨平台格式化: {cross_platform}")
|
|
96
|
+
|
|
97
|
+
# 时间字符串转日期
|
|
98
|
+
date_only = TimeUtils.convert_datetime_to_date('2025-01-01 12:30:45')
|
|
99
|
+
print(f"时间字符串转日期: {date_only}")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def example_advanced_usage():
|
|
103
|
+
"""高级使用示例"""
|
|
104
|
+
print("\n=== 高级使用示例 ===")
|
|
105
|
+
|
|
106
|
+
# 获取过去第n天的日期
|
|
107
|
+
past_5th_day = TimeUtils.get_past_nth_day(5)
|
|
108
|
+
print(f"过去第5天: {past_5th_day}")
|
|
109
|
+
|
|
110
|
+
# 获取过去n天的日期列表
|
|
111
|
+
past_10_days = TimeUtils.get_past_n_days_list(10)
|
|
112
|
+
print(f"过去10天列表: {past_10_days}")
|
|
113
|
+
|
|
114
|
+
# 获取从本月第一天到昨天的日期列表
|
|
115
|
+
month_dates = TimeUtils.get_dates_from_first_of_month_to_yesterday()
|
|
116
|
+
print(f"本月到昨天的日期: {month_dates}")
|
|
117
|
+
|
|
118
|
+
# 获取上个月的时间范围(字符串格式)
|
|
119
|
+
last_month_start_str, last_month_end_str = TimeUtils.get_last_month_range_time_str()
|
|
120
|
+
print(f"上个月时间范围: {last_month_start_str} 到 {last_month_end_str}")
|
|
121
|
+
|
|
122
|
+
# 获取上个月的时间范围(时间戳格式)
|
|
123
|
+
last_month_start_ts, last_month_end_ts = TimeUtils.get_last_month_range_time()
|
|
124
|
+
print(f"上个月时间戳范围: {last_month_start_ts} 到 {last_month_end_ts}")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def example_file_time():
|
|
128
|
+
"""文件时间相关示例"""
|
|
129
|
+
print("\n=== 文件时间相关示例 ===")
|
|
130
|
+
|
|
131
|
+
import os
|
|
132
|
+
|
|
133
|
+
# 创建一个临时文件用于测试
|
|
134
|
+
test_file = "test_file.txt"
|
|
135
|
+
with open(test_file, 'w') as f:
|
|
136
|
+
f.write("test content")
|
|
137
|
+
|
|
138
|
+
try:
|
|
139
|
+
# 获取文件修改时间
|
|
140
|
+
file_mtime = TimeUtils.get_file_mtime(test_file)
|
|
141
|
+
print(f"文件修改时间: {file_mtime}")
|
|
142
|
+
|
|
143
|
+
# 获取文件修改时间(datetime对象)
|
|
144
|
+
file_mtime_dt = TimeUtils.get_file_mtime(test_file, to_str=False)
|
|
145
|
+
print(f"文件修改时间(datetime): {file_mtime_dt}")
|
|
146
|
+
|
|
147
|
+
finally:
|
|
148
|
+
# 清理测试文件
|
|
149
|
+
if os.path.exists(test_file):
|
|
150
|
+
os.remove(test_file)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def example_weekday_functions():
|
|
154
|
+
"""星期相关函数示例"""
|
|
155
|
+
print("\n=== 星期相关函数示例 ===")
|
|
156
|
+
|
|
157
|
+
# 获取中文星期
|
|
158
|
+
weekday_cn = TimeUtils.get_chinese_weekday('2025-01-01')
|
|
159
|
+
print(f"2025-01-01 的中文星期: {weekday_cn}")
|
|
160
|
+
|
|
161
|
+
# 获取简短星期名称
|
|
162
|
+
weekday_short = TimeUtils.get_weekday_name('2025-01-01')
|
|
163
|
+
print(f"2025-01-01 的简短星期: {weekday_short}")
|
|
164
|
+
|
|
165
|
+
# 获取当前周数
|
|
166
|
+
week_num = TimeUtils.get_week_num()
|
|
167
|
+
print(f"当前是第 {week_num} 周")
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def example_period_functions():
|
|
171
|
+
"""时间段相关函数示例"""
|
|
172
|
+
print("\n=== 时间段相关函数示例 ===")
|
|
173
|
+
|
|
174
|
+
# 获取当前时间段(中文)
|
|
175
|
+
period_cn = TimeUtils.get_period()
|
|
176
|
+
print(f"当前时间段(中文): {period_cn}")
|
|
177
|
+
|
|
178
|
+
# 获取当前时间段(英文)
|
|
179
|
+
period_en = TimeUtils.get_period2()
|
|
180
|
+
print(f"当前时间段(英文): {period_en}")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def example_year_month_functions():
|
|
184
|
+
"""年月相关函数示例"""
|
|
185
|
+
print("\n=== 年月相关函数示例 ===")
|
|
186
|
+
|
|
187
|
+
# 获取当前年份
|
|
188
|
+
current_year = TimeUtils.get_current_year()
|
|
189
|
+
print(f"当前年份: {current_year}")
|
|
190
|
+
|
|
191
|
+
# 获取当前月份
|
|
192
|
+
current_month = TimeUtils.get_current_month()
|
|
193
|
+
print(f"当前月份: {current_month}")
|
|
194
|
+
|
|
195
|
+
# 获取上个月
|
|
196
|
+
last_month = TimeUtils.get_last_month()
|
|
197
|
+
print(f"上个月: {last_month}")
|
|
198
|
+
|
|
199
|
+
# 获取当前年份范围
|
|
200
|
+
year_start, year_end = TimeUtils.get_current_year_range()
|
|
201
|
+
print(f"当前年份范围: {year_start} 到 {year_end}")
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def example_relative_dates():
|
|
205
|
+
"""相对日期函数示例"""
|
|
206
|
+
print("\n=== 相对日期函数示例 ===")
|
|
207
|
+
|
|
208
|
+
# 获取昨天
|
|
209
|
+
yesterday = TimeUtils.get_yesterday()
|
|
210
|
+
print(f"昨天: {yesterday}")
|
|
211
|
+
|
|
212
|
+
# 获取前天
|
|
213
|
+
before_yesterday = TimeUtils.before_yesterday()
|
|
214
|
+
print(f"前天: {before_yesterday}")
|
|
215
|
+
|
|
216
|
+
# 获取明天
|
|
217
|
+
tomorrow = TimeUtils.tomorrow_date()
|
|
218
|
+
print(f"明天: {tomorrow}")
|
|
219
|
+
|
|
220
|
+
# 基于指定日期获取昨天
|
|
221
|
+
yesterday_from_date = TimeUtils.get_yesterday('20250101')
|
|
222
|
+
print(f"基于2025-01-01的昨天: {yesterday_from_date}")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
if __name__ == "__main__":
|
|
226
|
+
"""运行所有示例"""
|
|
227
|
+
print("时间工具模块使用示例")
|
|
228
|
+
print("=" * 50)
|
|
229
|
+
|
|
230
|
+
example_basic_usage()
|
|
231
|
+
example_date_ranges()
|
|
232
|
+
example_timestamp_conversion()
|
|
233
|
+
example_date_comparison()
|
|
234
|
+
example_date_formatting()
|
|
235
|
+
example_advanced_usage()
|
|
236
|
+
example_file_time()
|
|
237
|
+
example_weekday_functions()
|
|
238
|
+
example_period_functions()
|
|
239
|
+
example_year_month_functions()
|
|
240
|
+
example_relative_dates()
|
|
241
|
+
|
|
242
|
+
print("\n" + "=" * 50)
|
|
243
|
+
print("所有示例运行完成!")
|