feat(daily-challenge): show statistics in profile

This commit is contained in:
MingxuanGame
2025-08-20 04:24:00 +00:00
parent 0b3e725eea
commit ef1b699547
5 changed files with 157 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from datetime import datetime
def unix_timestamp_to_windows(timestamp: int) -> int:
"""Convert a Unix timestamp to a Windows timestamp."""
@@ -90,3 +92,29 @@ def snake_to_pascal(name: str, use_abbr: bool = True) -> str:
result.append(part.capitalize())
return "".join(result)
def are_adjacent_weeks(dt1: datetime, dt2: datetime) -> bool:
y1, w1, _ = dt1.isocalendar()
y2, w2, _ = dt2.isocalendar()
# 按 (年, 周) 排序,保证 dt1 <= dt2
if (y1, w1) > (y2, w2):
y1, w1, y2, w2 = y2, w2, y1, w1
# 同一年,周数相邻
if y1 == y2 and w2 - w1 == 1:
return True
# 跨年,判断 y2 是否是下一年,且 w2 == 1并且 w1 是 y1 的最后一周
if y2 == y1 + 1 and w2 == 1:
# 判断 y1 的最后一周是多少
last_week_y1 = datetime(y1, 12, 28).isocalendar()[1] # 12-28 保证在最后一周
if w1 == last_week_y1:
return True
return False
def are_same_weeks(dt1: datetime, dt2: datetime) -> bool:
return dt1.isocalendar()[:2] == dt2.isocalendar()[:2]