fix: sliding period window for datetime precision
After --commit with precision=datetime, last_used held from==to==now, so the next default period degenerated to a single second and showed no new time entries. Now --commit stores the real report window start and get_default_date_range() returns last_used.to..now for datetime+dynamic mode. Closes #70
This commit is contained in:
@@ -580,10 +580,9 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
dynamic = Config._app.period_dynamic if Config._app else False
|
||||
|
||||
if precision == "datetime":
|
||||
# Сохраняем aware UTC (#58): следующий запуск вычисляет из этой
|
||||
# метки aware cutoff для дедупликации.
|
||||
now = datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||
from_str = now
|
||||
# from -- фактическое начало окна отчёта; to -- дедуп-маркер (naive UTC).
|
||||
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")
|
||||
from_str = from_date
|
||||
to_str = now
|
||||
else:
|
||||
from_str = from_date
|
||||
|
||||
@@ -2,7 +2,7 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import date, timedelta
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
from typing import Dict, Union
|
||||
|
||||
@@ -440,6 +440,23 @@ class Config:
|
||||
if from_env:
|
||||
return f"{from_env}--{to_env or today_str}"
|
||||
|
||||
if (
|
||||
cls._app
|
||||
and cls._app.period_dynamic
|
||||
and (cls._app.period_precision or "date") == "datetime"
|
||||
and cls._app.period_last_used_to
|
||||
):
|
||||
last_to = datetime.fromisoformat(
|
||||
cls._app.period_last_used_to.replace("Z", "+00:00")
|
||||
)
|
||||
if last_to.tzinfo is None:
|
||||
last_to = last_to.replace(tzinfo=timezone.utc)
|
||||
else:
|
||||
last_to = last_to.astimezone(timezone.utc)
|
||||
now_utc = datetime.now(timezone.utc)
|
||||
fmt = "%Y-%m-%dT%H:%M:%S"
|
||||
return f"{last_to.strftime(fmt)}--{now_utc.strftime(fmt)}"
|
||||
|
||||
if (
|
||||
cls._app
|
||||
and cls._app.period_dynamic
|
||||
|
||||
Reference in New Issue
Block a user