ph-utils 0.1.2__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ph-utils
3
- Version: 0.1.2
3
+ Version: 0.2.1
4
4
  Summary: The python3 tool classes
5
5
  Author: Tenny
6
6
  Author-email: Tenny <tenny.shu@foxmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ph-utils"
3
- version = "0.1.2"
3
+ version = "0.2.1"
4
4
  description = "The python3 tool classes"
5
5
  authors = [
6
6
  { name = "Tenny", email = "tenny.shu@foxmail.com" },
@@ -246,51 +246,125 @@ def _plus_year(ori_date: datetime, year: int) -> datetime:
246
246
  return ori_date.replace(year=new_year)
247
247
 
248
248
 
249
- def add(ori_date: OriDateType = None, delta: DeltaDict | None = None) -> datetime:
249
+ def add(
250
+ ori_date: OriDateType = None,
251
+ *,
252
+ days: int | float = 0,
253
+ months: int = 0,
254
+ years: int = 0,
255
+ weeks: int | float = 0,
256
+ hours: int | float = 0,
257
+ minutes: int | float = 0,
258
+ seconds: int | float = 0,
259
+ microseconds: int | float = 0,
260
+ milliseconds: int | float = 0,
261
+ ) -> datetime:
250
262
  """将日期进行加法操作, 通常用于计算几天、几月、几年之后的日期
251
263
 
252
264
  Args:
253
265
  ori_date (datetime | str, optional): 待添加的日期. Defaults to None.
254
- delta (dict, optional): { days - 天, months - 月, years - 年, hours - 小时, minutes - 分钟, seconds - 秒 }. Defaults to None.
266
+ days (int | float, optional): 天数. Defaults to 0.
267
+ months (int, optional): 月数. Defaults to 0.
268
+ years (int, optional): 年数. Defaults to 0.
269
+ weeks (int | float, optional): 周数. Defaults to 0.
270
+ hours (int | float, optional): 小时数. Defaults to 0.
271
+ minutes (int | float, optional): 分钟数. Defaults to 0.
272
+ seconds (int | float, optional): 秒数. Defaults to 0.
273
+ microseconds (int | float, optional): 微秒数. Defaults to 0.
274
+ milliseconds (int | float, optional): 毫秒数. Defaults to 0.
255
275
 
256
276
  Returns:
257
277
  datetime: 添加后的日期
258
278
  """
259
- if not delta:
260
- delta = {"days": 0}
261
279
  ori_date = parse(ori_date)
262
- if "years" in delta: # 年份
263
- ori_date = _plus_year(ori_date, delta["years"])
264
- del delta["years"]
265
- if "months" in delta: # 月份
266
- ori_date = _plus_month(ori_date, delta["months"])
267
- del delta["months"]
268
- if delta:
269
- diff = timedelta(**delta)
270
- ori_date = ori_date + diff
280
+ if years:
281
+ ori_date = _plus_year(ori_date, years)
282
+ if months:
283
+ ori_date = _plus_month(ori_date, months)
284
+
285
+ diff = timedelta(
286
+ days=days,
287
+ weeks=weeks,
288
+ hours=hours,
289
+ minutes=minutes,
290
+ seconds=seconds,
291
+ microseconds=microseconds,
292
+ milliseconds=milliseconds,
293
+ )
294
+ ori_date = ori_date + diff
271
295
  return ori_date
272
296
 
273
297
 
274
- def subtract(ori_date: OriDateType = None, delta: DeltaDict | None = None):
275
- """将日期进行加法操作, 通常用于计算几天、几月、几年之前的日期
298
+ def subtract(
299
+ ori_date: OriDateType = None,
300
+ *,
301
+ days: int | float = 0,
302
+ months: int = 0,
303
+ years: int = 0,
304
+ weeks: int | float = 0,
305
+ hours: int | float = 0,
306
+ minutes: int | float = 0,
307
+ seconds: int | float = 0,
308
+ microseconds: int | float = 0,
309
+ milliseconds: int | float = 0,
310
+ ):
311
+ """将日期进行减法操作, 通常用于计算几天、几月、几年之前的日期
276
312
 
277
313
  Args:
278
314
  ori_date (datetime | str, optional): 原始日期. Defaults to None.
279
- delta (dict, optional): { days - 天, months - 月, years - 年 }. Defaults to None.
315
+ days (int | float, optional): 天数. Defaults to 0.
316
+ months (int, optional): 月数. Defaults to 0.
317
+ years (int, optional): 年数. Defaults to 0.
318
+ weeks (int | float, optional): 周数. Defaults to 0.
319
+ hours (int | float, optional): 小时数. Defaults to 0.
320
+ minutes (int | float, optional): 分钟数. Defaults to 0.
321
+ seconds (int | float, optional): 秒数. Defaults to 0.
322
+ microseconds (int | float, optional): 微秒数. Defaults to 0.
323
+ milliseconds (int | float, optional): 毫秒数. Defaults to 0.
280
324
 
281
325
  Returns:
282
- datetime: 添加后的日期
326
+ datetime: 减去之后的日期
283
327
  """
284
- if not delta:
285
- delta = {"days": 0}
286
- for key in delta:
287
- delta[key] = -delta[key]
288
- return add(ori_date, delta)
289
-
290
-
291
- def sub(ori_date: OriDateType = None, delta: DeltaDict | None = None):
328
+ return add(
329
+ ori_date,
330
+ days=-days,
331
+ months=-months,
332
+ years=-years,
333
+ weeks=-weeks,
334
+ hours=-hours,
335
+ minutes=-minutes,
336
+ seconds=-seconds,
337
+ microseconds=-microseconds,
338
+ milliseconds=-milliseconds,
339
+ )
340
+
341
+
342
+ def sub(
343
+ ori_date: OriDateType = None,
344
+ *,
345
+ days: int | float = 0,
346
+ months: int = 0,
347
+ years: int = 0,
348
+ weeks: int | float = 0,
349
+ hours: int | float = 0,
350
+ minutes: int | float = 0,
351
+ seconds: int | float = 0,
352
+ microseconds: int | float = 0,
353
+ milliseconds: int | float = 0,
354
+ ):
292
355
  """subtract 函数别名"""
293
- return subtract(ori_date, delta)
356
+ return subtract(
357
+ ori_date,
358
+ days=days,
359
+ months=months,
360
+ years=years,
361
+ weeks=weeks,
362
+ hours=hours,
363
+ minutes=minutes,
364
+ seconds=seconds,
365
+ microseconds=microseconds,
366
+ milliseconds=milliseconds,
367
+ )
294
368
 
295
369
 
296
370
  @overload
File without changes
File without changes