forked from mtusi2026/mtusi2026lab4
chore: carry lab 3 over
- carry the lab 3 solution over from mtusi2026lab3-safronov (solution/bvt2301-safronov, ce89eba): src, migrations, student-tests, bench, openspec, .claude, infra/haproxy and infra/valkey, own scripts, Dockerfile, compose, pyproject and uv lock - merge Makefile, .gitignore and .dockerignore (the lab 3 versions only add lines to the skeleton, which is the same in lab 4) and .env.example (lab 4 skeleton names listed in the header) - rename the compose project to mtusi-lab4 and the image to :lab4 so the stand does not reuse the lab 3 containers and volumes - update AGENTS.md for lab 4: current lab, origin commit, contract and test files of the new skeleton Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
from datetime import UTC, datetime
|
||||
|
||||
# RFC 3339 в UTC, всегда шесть знаков микросекунд и суффикс Z
|
||||
RFC3339_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
|
||||
|
||||
|
||||
def utcnow() -> datetime:
|
||||
"""Текущее время в UTC (aware), с микросекундами."""
|
||||
return datetime.now(UTC)
|
||||
|
||||
|
||||
def to_rfc3339(value: datetime) -> str:
|
||||
"""Время для API и курсора: `2026-09-01T12:00:00.000000Z`."""
|
||||
# isoformat вместо strftime: та же строка дешевле, а вызов идёт на
|
||||
# каждое сообщение страницы. После astimezone(UTC) смещение — «+00:00»
|
||||
text = value.astimezone(UTC).isoformat(timespec="microseconds")
|
||||
return text[:-6] + "Z"
|
||||
|
||||
|
||||
def from_rfc3339(value: str) -> datetime:
|
||||
"""Обратное к `to_rfc3339`; бросает `ValueError` на другой формат."""
|
||||
return datetime.strptime(value, RFC3339_FORMAT).replace(tzinfo=UTC)
|
||||
Reference in New Issue
Block a user