patch 5c25f44f55e071966feef397617ebfeea52dd88c
Author: E. Bosch <presidev@AT@gmail.com>
Date:   Sun May  7 01:31:34 CEST 2023
  * telegram: Add an option to enable and control format of timestamps for history messages
  Add timezone option to convert timestamps
hunk ./README.md 54
-- [python] (>= v3.8)
+- [python] (>= v3.9)
hunk ./irgramd 76
+    tornado.options.define('hist_timestamp_format', metavar='DATETIME_FORMAT', help='Format string for timestamps in history, see https://www.strfti.me')
hunk ./irgramd 91
+    tornado.options.define('timezone', default='UTC', metavar='TIMEZONE', help='Timezone to use for dates (timestamps in history, last in dialogs, etc.)')
hunk ./service.py 206
-                await self.tg.handle_telegram_message(event=None, message=msg)
+                await self.tg.handle_telegram_message(event=None, message=msg, history=True)
hunk ./telegram.py 25
-from utils import sanitize_filename, is_url_equiv, extract_url, get_human_size, get_human_duration, get_highlighted, fix_braces
+from utils import sanitize_filename, is_url_equiv, extract_url, get_human_size, get_human_duration, get_highlighted, fix_braces, format_timestamp
hunk ./telegram.py 51
+        self.hist_fmt   = settings['hist_timestamp_format']
+        self.timezone   = settings['timezone']
hunk ./telegram.py 453
-    async def handle_telegram_message(self, event, message=None, upd_to_webpend=None):
+    async def handle_telegram_message(self, event, message=None, upd_to_webpend=None, history=False):
hunk ./telegram.py 461
-        chan = await self.relay_telegram_message(msg, user, text)
+        text_send = self.set_history_timestamp(text, history, msg.date)
+        chan = await self.relay_telegram_message(msg, user, text_send)
hunk ./telegram.py 468
-    async def render_text(self, message, mid, upd_to_webpend):
+    async def render_text(self, message, mid, upd_to_webpend, history=False):
hunk ./telegram.py 487
+    def set_history_timestamp(self, text, history, date):
+        if history and self.hist_fmt:
+            timestamp = format_timestamp(self.hist_fmt, self.timezone, date)
+            res = '{} {}'.format(timestamp, text)
+        else:
+            res = text
+        return res
+
hunk ./utils.py 14
+import zoneinfo
hunk ./utils.py 175
+
+def format_timestamp(format, tz, date):
+    date_local = date.astimezone(zoneinfo.ZoneInfo(tz))
+    return date_local.strftime(format)