utils: Add current_date() shortcut
patch 799dcf8a6a7c8346af93e7f17841baf08db70e7c
Author: E. Bosch <presidev@AT@gmail.com>
Date: Fri Aug 30 01:58:06 CEST 2024
* utils: Add current_date() shortcut
diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py
--- old-irgramd/telegram.py 2024-11-22 10:39:18.881336772 +0100
+++ new-irgramd/telegram.py 2024-11-22 10:39:18.885336766 +0100
@@ -9,7 +9,6 @@
import logging
import os
-import datetime
import re
import aioconsole
import asyncio
@@ -22,7 +21,8 @@
from include import CHAN_MAX_LENGHT, NICK_MAX_LENGTH
from irc import IRCUser
-from utils import sanitize_filename, add_filename, is_url_equiv, extract_url, get_human_size, get_human_duration, get_highlighted, fix_braces, format_timestamp, pretty
+from utils import sanitize_filename, add_filename, is_url_equiv, extract_url, get_human_size, get_human_duration
+from utils import get_highlighted, fix_braces, format_timestamp, pretty, current_date
import emoji2emoticon as e
# Test IP table
@@ -286,7 +286,7 @@
idle = 0
elif isinstance(user.status,tgty.UserStatusOffline):
last = user.status.was_online
- current = datetime.datetime.now(datetime.timezone.utc)
+ current = current_date()
idle = int((current - last).total_seconds())
elif isinstance(user.status,tgty.UserStatusLastWeek):
idle = 604800
diff -rN -u old-irgramd/utils.py new-irgramd/utils.py
--- old-irgramd/utils.py 2024-11-22 10:39:18.881336772 +0100
+++ new-irgramd/utils.py 2024-11-22 10:39:18.885336766 +0100
@@ -152,7 +152,7 @@
return res
def compact_date(date, tz):
- delta = datetime.datetime.now(datetime.timezone.utc) - date
+ delta = current_date() - date
date_local = date.astimezone(zoneinfo.ZoneInfo(tz))
if delta.days < 1:
@@ -164,6 +164,9 @@
return compact_date
+def current_date():
+ return datetime.datetime.now(datetime.timezone.utc)
+
def get_highlighted(a, b):
awl = len(a.split())
bwl = len(b.split())