duqing2026 commited on
Commit
4086fa5
·
1 Parent(s): 21ae939

统计同一改为北京时间

Browse files
Files changed (2) hide show
  1. app.py +4 -3
  2. scripts/gen_stats.py +5 -5
app.py CHANGED
@@ -345,7 +345,8 @@ PROJECT_TYPES = [
345
  ]
346
 
347
  def _now() -> str:
348
- return datetime.datetime.utcnow().isoformat()
 
349
 
350
  class DataStore:
351
  def __init__(self):
@@ -390,7 +391,7 @@ class DataStore:
390
  now_utc = datetime.datetime.utcnow()
391
  beijing_now = now_utc + datetime.timedelta(hours=8)
392
  beijing_today_start = beijing_now.replace(hour=0, minute=0, second=0, microsecond=0)
393
- start_iso = (beijing_today_start - datetime.timedelta(hours=8)).isoformat()
394
 
395
  try:
396
  with open(VISITS_FILE, "r", encoding="utf-8") as f:
@@ -467,7 +468,7 @@ class DataStore:
467
  now_utc = datetime.datetime.utcnow()
468
  beijing_now = now_utc + datetime.timedelta(hours=8)
469
  beijing_today_start = beijing_now.replace(hour=0, minute=0, second=0, microsecond=0)
470
- start_iso = (beijing_today_start - datetime.timedelta(hours=8)).isoformat()
471
 
472
  if start_iso > self.stats_cache["last_update"]:
473
  # New day, reset today count (approximate, strictly should re-read or track timestamps in memory, but for efficiency reset is ok if we assume monotonic)
 
345
  ]
346
 
347
  def _now() -> str:
348
+ # Use Beijing Time (UTC+8)
349
+ return (datetime.datetime.utcnow() + datetime.timedelta(hours=8)).isoformat()
350
 
351
  class DataStore:
352
  def __init__(self):
 
391
  now_utc = datetime.datetime.utcnow()
392
  beijing_now = now_utc + datetime.timedelta(hours=8)
393
  beijing_today_start = beijing_now.replace(hour=0, minute=0, second=0, microsecond=0)
394
+ start_iso = beijing_today_start.isoformat()
395
 
396
  try:
397
  with open(VISITS_FILE, "r", encoding="utf-8") as f:
 
468
  now_utc = datetime.datetime.utcnow()
469
  beijing_now = now_utc + datetime.timedelta(hours=8)
470
  beijing_today_start = beijing_now.replace(hour=0, minute=0, second=0, microsecond=0)
471
+ start_iso = beijing_today_start.isoformat()
472
 
473
  if start_iso > self.stats_cache["last_update"]:
474
  # New day, reset today count (approximate, strictly should re-read or track timestamps in memory, but for efficiency reset is ok if we assume monotonic)
scripts/gen_stats.py CHANGED
@@ -9,12 +9,12 @@ TARGET_TODAY = 63
9
  TODAY_DATE = "2026-01-24" # Based on system time
10
 
11
  # Timezone (UTC+8 for "today" calculation logic in app.py)
12
- # app.py uses: now = datetime.now(timezone(timedelta(hours=8)))
13
- # and checks if visit_time.date() == now.date()
14
 
15
- TZ_CN = timezone(timedelta(hours=8))
16
- now_cn = datetime.now(TZ_CN)
17
- # Force "today" to be consistent with user request (assuming user means "now")
18
  start_of_today = now_cn.replace(hour=0, minute=0, second=0, microsecond=0)
19
 
20
  visits = []
 
9
  TODAY_DATE = "2026-01-24" # Based on system time
10
 
11
  # Timezone (UTC+8 for "today" calculation logic in app.py)
12
+ # app.py now uses naive Beijing time string (UTC+8) for created_at
13
+ # e.g., "2023-01-01T12:00:00.000000" (representing 12:00 Beijing time)
14
 
15
+ now_utc = datetime.utcnow()
16
+ now_cn = now_utc + timedelta(hours=8)
17
+ # Force "today" to be consistent with user request
18
  start_of_today = now_cn.replace(hour=0, minute=0, second=0, microsecond=0)
19
 
20
  visits = []