Time zone handling
Build and Push CodeReview / build (push) Waiting to run Details

This commit is contained in:
vinland100 2026-01-09 13:36:12 +08:00
parent 3ce3767938
commit dfefdfe432
1 changed files with 13 additions and 5 deletions

View File

@ -13,9 +13,17 @@ def get_now_iso():
def beijing_time(*args):
"""
用于 logging.Formatter.converter 的转换函数
用于 logging.Formatter.converter 的转换函数
支持 (timestamp) (formatter, timestamp) 调用形式
"""
if args:
# args[0] 是 timestamp
return datetime.fromtimestamp(args[0], CHINA_TZ).timetuple()
return get_now().timetuple()
if len(args) == 2:
# 被作为 bound method 调用: (self, timestamp)
ts = args[1]
elif len(args) == 1:
# 被作为普通函数调用: (timestamp)
ts = args[0]
else:
# 无参数调用(不常见,但作为兜底)
ts = datetime.now().timestamp()
return datetime.fromtimestamp(ts, CHINA_TZ).timetuple()