瀏覽代碼

fix: "minute must be in 0..59" error (#20)

tags/v0.11.2
Jérôme Deuchnord 3 年之前
committed by GitHub
父節點
當前提交
592f8b15d0
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 1 個文件被更改,包括 13 次插入7 次删除
  1. +13
    -7
      kosmorrolib/dateutil.py

+ 13
- 7
kosmorrolib/dateutil.py 查看文件

@@ -22,11 +22,17 @@ def normalize_datetime(date: datetime) -> datetime:

>>> normalize_datetime(datetime(2021, 6, 9, 2, 30, 30))
datetime.datetime(2021, 6, 9, 2, 31)

>>> normalize_datetime(datetime(2021, 6, 9, 23, 59, 59))
datetime.datetime(2021, 6, 10, 0, 0)

>>> normalize_datetime(datetime(2021, 12, 31, 23, 59, 59))
datetime.datetime(2022, 1, 1, 0, 0)
"""
return datetime(
date.year,
date.month,
date.day,
date.hour,
date.minute if date.second < 30 else date.minute + 1,
)
new_date = datetime(date.year, date.month, date.day, date.hour, date.minute)
if date.second >= 30:
new_date += timedelta(minutes=1)
return new_date

Loading…
取消
儲存