feat(cli): time --tz 时区偏移(默认本机时区的修正项),151 测试全绿
This commit is contained in:
1 parent
29e4c2b10c
commit
2c10e6b3c8
2 files changed
+18
No files matched your search
@@ -286,3 +286,17 @@ class TestViaBridge:
|
||||
code, _ = run_cli(capsys, ["--json", "scan"])
|
||||
assert code == 0
|
||||
assert called["args"] == ("10.0.0.7", 8971)
|
||||
|
||||
|
||||
class TestTimeTz:
|
||||
def test_tz_offset_applied(self, capsys, monkeypatch):
|
||||
"""--tz 8 应写入北京墙钟(与系统 UTC 本地时相差 8h)"""
|
||||
import datetime as _dt
|
||||
code, out = run_cli(capsys, ["--json", "time", "--tz", "8"])
|
||||
assert code == 0
|
||||
sent = FakeTransport.instances[0].rxtx_writes[0]
|
||||
# dd 帧的 unix 字段(本地墙钟按 UTC 计)反解小时
|
||||
unix_local = int.from_bytes(sent[1:5], "big")
|
||||
wall = _dt.datetime.fromtimestamp(unix_local, _dt.timezone.utc)
|
||||
utc_now = _dt.datetime.now(_dt.timezone.utc)
|
||||
assert abs((wall - utc_now).total_seconds() - 8 * 3600) < 120
|
||||
Reference in new issue
Block a user