fix(time): report Beijing wall clock independently of server timezone
This commit is contained in:
@@ -4,7 +4,7 @@ import json
|
|||||||
import secrets
|
import secrets
|
||||||
import ssl
|
import ssl
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import quote, urlsplit
|
from urllib.parse import quote, urlsplit
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ class WorkClient:
|
|||||||
try:
|
try:
|
||||||
token = self.access_token()
|
token = self.access_token()
|
||||||
return {"authorized": True, "owner": self.owner, "message": "本人用户授权可用;令牌未输出。",
|
return {"authorized": True, "owner": self.owner, "message": "本人用户授权可用;令牌未输出。",
|
||||||
"local_time": datetime.now().astimezone().isoformat()}
|
"local_time": datetime.now(timezone(timedelta(hours=8))).isoformat()}
|
||||||
except AuthorizationRequired as error:
|
except AuthorizationRequired as error:
|
||||||
return {"authorized": False, "authorization_url": error.url, "message": str(error)}
|
return {"authorized": False, "authorization_url": error.url, "message": str(error)}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from relay import work_client
|
||||||
|
|
||||||
|
|
||||||
|
def test_legacy_status_is_beijing_even_on_utc_host(monkeypatch):
|
||||||
|
class Clock:
|
||||||
|
@staticmethod
|
||||||
|
def now(tz=None):
|
||||||
|
instant=datetime(2026,11,5,17,30,tzinfo=timezone.utc)
|
||||||
|
return instant.astimezone(tz) if tz else instant
|
||||||
|
monkeypatch.setattr(work_client,'datetime',Clock)
|
||||||
|
client=object.__new__(work_client.WorkClient)
|
||||||
|
client.owner='synthetic-owner'
|
||||||
|
client.access_token=lambda:'synthetic-token'
|
||||||
|
result=client.status()
|
||||||
|
assert result['local_time']=='2026-11-06T01:30:00+08:00'
|
||||||
|
assert 'synthetic-token' not in str(result)
|
||||||
Reference in New Issue
Block a user