Date now and a reset each in its own UTC offset
This commit is contained in:
+6
-7
@@ -6,7 +6,6 @@ import math
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
CYAN = "\033[36m"
|
||||
DIM = "\033[2m"
|
||||
@@ -92,15 +91,15 @@ def humanize_tokens(count: int) -> str:
|
||||
return str(count)
|
||||
|
||||
|
||||
def reset_suffix(at: datetime.datetime, now: int) -> str:
|
||||
seconds = max(0, int(at.timestamp()) - now)
|
||||
def reset_suffix(at: datetime.datetime, now: datetime.datetime) -> str:
|
||||
seconds = max(0, int((at - now).total_seconds()))
|
||||
if seconds >= 86400:
|
||||
left = f"{seconds // 86400}d{seconds % 86400 // 3600}h"
|
||||
elif seconds >= 3600:
|
||||
left = f"{seconds // 3600}h{seconds % 3600 // 60}m"
|
||||
else:
|
||||
left = f"{seconds // 60}m"
|
||||
clock = at.strftime("%H:%M" if at.date() == datetime.datetime.fromtimestamp(now, at.tzinfo).date() else "%a %H:%M")
|
||||
clock = at.strftime("%H:%M" if at.date() == now.date() else "%a %H:%M")
|
||||
return f" {DIM}{left} left ({clock}){RESET}"
|
||||
|
||||
|
||||
@@ -109,13 +108,13 @@ def usage_segment(label: str, percent: float, suffix: str) -> str:
|
||||
return f"{DIM}{label}{RESET} {usage_color(rounded)}{rounded}%{RESET}{suffix}"
|
||||
|
||||
|
||||
def limit_segment(label: str, window: Limit | None, now: int) -> list[str]:
|
||||
def limit_segment(label: str, window: Limit | None, now: datetime.datetime) -> list[str]:
|
||||
if window is None:
|
||||
return []
|
||||
return [usage_segment(label, window.percent, "" if window.resets_at is None else reset_suffix(window.resets_at, now))]
|
||||
|
||||
|
||||
def render(status: Status, branch: str, home: str, now: int) -> str:
|
||||
def render(status: Status, branch: str, home: str, now: datetime.datetime) -> str:
|
||||
where = []
|
||||
if status.directory:
|
||||
shown = status.directory
|
||||
@@ -156,7 +155,7 @@ def main() -> str:
|
||||
return f"{RED}warning: statusline.py could not parse its input as a JSON object{RESET}"
|
||||
# Zone None: astimezone converts to the machine's own zone, daylight saving included.
|
||||
status = parse(raw, None)
|
||||
return render(status, current_branch(status.directory), os.environ.get("HOME", ""), int(time.time()))
|
||||
return render(status, current_branch(status.directory), os.environ.get("HOME", ""), datetime.datetime.now().astimezone())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user