@@ -33,12 +33,21 @@ assessment_lower_bound() {
3333import sys
3434from datetime import datetime, timedelta, timezone
3535stage, started_at, window = sys.argv[1:]
36- start = datetime.fromisoformat(started_at.replace("Z", "+00:00"))
36+ def parse_rfc3339(value):
37+ base, fraction = value.rstrip("Z").split(".", 1) if "." in value else (value.rstrip("Z"), "")
38+ return (datetime.fromisoformat(base).replace(tzinfo=timezone.utc), int((fraction + "0" * 9)[:9]))
39+
40+ def render(value):
41+ moment, nanos = value
42+ return moment.strftime("%Y-%m-%dT%H:%M:%S") + ".%09dZ" % nanos
43+
44+ start = parse_rfc3339(started_at)
3745if stage == "initial":
38- lower = max(start, datetime.now(timezone.utc) - timedelta(seconds=int(window)))
46+ now = datetime.now(timezone.utc) - timedelta(seconds=int(window))
47+ lower = max(start, (now.replace(microsecond=0), now.microsecond * 1000))
3948else:
4049 lower = start
41- print(lower.isoformat(timespec="microseconds").replace("+00:00", "Z" ))
50+ print(render(lower ))
4251PY
4352}
4453
@@ -59,7 +68,13 @@ snapshot_decision() {
5968 } | python3 -c '
6069import re, sys
6170from datetime import datetime, timezone
62- lower = datetime.fromisoformat(sys.argv[1].replace("Z", "+00:00"))
71+ def parse_stamp(value):
72+ match = re.fullmatch(r"(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d)(?:\.(\d{1,9}))?Z", value)
73+ if not match:
74+ raise ValueError("invalid timestamp")
75+ return (datetime.fromisoformat(match.group(1)).replace(tzinfo=timezone.utc), int(((match.group(2) or "") + "0" * 9)[:9]))
76+
77+ lower = parse_stamp(sys.argv[1])
6378terminal = re.compile(r"IBC closing because login has not completed|(?:authentication|login).*(?:timeout|timed out|failed)", re.I)
6479progress = re.compile(r"IBC: (Starting Gateway|Login attempt|Second Factor Authentication|Login has completed|Configuration tasks completed)|Authentication window found|Auto-fill submitted|Passed token authentication|Authentication completed|Security code:", re.I)
6580seen_progress = False
@@ -69,7 +84,7 @@ for raw in sys.stdin:
6984 except ValueError: print("invalid"); raise SystemExit
7085 m = re.match(r"(\d{4}-\d\d-\d\d[T ]\d\d:\d\d:\d\d)(?:[.,:](\d{1,9}))?Z?", line)
7186 if not m: continue
72- stamp = datetime.fromisoformat(( m.group(1).replace(" ", "T") + "." + ( m.group(2) or "0 ") + "+00:00" ))
87+ stamp = ( datetime.fromisoformat(m.group(1).replace(" ", "T")).replace(tzinfo=timezone.utc), int((( m.group(2) or "") + "0" * 9)[:9] ))
7388 if stamp < lower: continue
7489 if terminal.search(line): print("terminal"); raise SystemExit
7590 if progress.search(line): seen_progress = True
0 commit comments