fix: use local timezone for --today and --days filters in food_log
This commit is contained in:
parent
4453fd1daa
commit
15edd083b1
1 changed files with 6 additions and 2 deletions
|
|
@ -52,10 +52,14 @@ def cmd_get(args):
|
||||||
if args.type:
|
if args.type:
|
||||||
query["type"] = {"$regex": args.type, "$options": "i"}
|
query["type"] = {"$regex": args.type, "$options": "i"}
|
||||||
if args.today:
|
if args.today:
|
||||||
today_start = datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
|
local_now = datetime.now().astimezone()
|
||||||
|
local_midnight = local_now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
today_start = local_midnight.astimezone(timezone.utc)
|
||||||
query["timestamp"] = {"$gte": today_start}
|
query["timestamp"] = {"$gte": today_start}
|
||||||
if args.days:
|
if args.days:
|
||||||
cutoff = datetime.now(timezone.utc) - timedelta(days=args.days)
|
local_now = datetime.now().astimezone()
|
||||||
|
cutoff_local = local_now - timedelta(days=args.days)
|
||||||
|
cutoff = cutoff_local.astimezone(timezone.utc)
|
||||||
query["timestamp"] = {"$gte": cutoff}
|
query["timestamp"] = {"$gte": cutoff}
|
||||||
|
|
||||||
cursor = coll.find(query).sort("timestamp", -1).limit(args.limit if args.limit else 50)
|
cursor = coll.find(query).sort("timestamp", -1).limit(args.limit if args.limit else 50)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue