From 58fb98b5d69a1b81248b089cf1b6ac0172be9c01 Mon Sep 17 00:00:00 2001
From: MxMarx <ruby.e.marx@gmail.com>
Date: Fri, 15 Sep 2023 17:47:03 -0700
Subject: [PATCH] add time_format parameter

---
 base-config.yaml     | 14 ++++++++++++--
 reminder/bot.py      |  2 ++
 reminder/reminder.py |  8 ++++----
 reminder/util.py     |  9 ++++-----
 4 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/base-config.yaml b/base-config.yaml
index e44fc98..1e0fc93 100644
--- a/base-config.yaml
+++ b/base-config.yaml
@@ -1,3 +1,6 @@
+# https://github.com/MxMarx/reminder
+# Feature requests welcome!
+
 # Default timezone for users who did not set one.
 # This is parsed with dateparser, so Continent/City, UTC offsets, and abbreviations should work.
 #  e.g. Europe/Helsinki, EET, +0300
@@ -14,7 +17,8 @@ base_command:
 - remind
 - remindme
 
-# subcommands used to create an agenda items
+# Agenda items are like reminders but don't have a time, for things like to-do lists.
+# Aliases used to create an agenda items by calling "!agenda <message>":
 agenda_command:
 - agenda
 - todo
@@ -24,7 +28,6 @@ cancel_command:
 - cancel
 - delete
 
-
 # If verbose is true, display full confirmation messages. If false, confirm by reacting with :thumbs-up:
 verbose: true
 
@@ -32,4 +35,11 @@ verbose: true
 rate_limit: 10
 rate_limit_minutes: 60
 
+# Power level needed to delete someone else's reminder
 admin_power_level: 50
+
+# time_format: strftime format when listing reminders.
+#   "%-I:%M%P %Z on %A, %B %-d %Y"  - 7:36pm PDT on Sunday, September 17 2023
+#   "%Y-%m-%d %H:%M %Z"             - 2023-09-17 19:36 PDT
+#   Currently, reminders within 7 days will be displayed as just the relative delta, e.g. "2 days and 1 hour"
+time_format: "%-I:%M%P %Z on %A, %B %-d %Y"
\ No newline at end of file
diff --git a/reminder/bot.py b/reminder/bot.py
index d70e9e8..41043d8 100644
--- a/reminder/bot.py
+++ b/reminder/bot.py
@@ -44,6 +44,8 @@ class Config(BaseProxyConfig):
         helper.copy("rate_limit")
         helper.copy("verbose")
         helper.copy("admin_power_level")
+        helper.copy("time_format")
+
 
 class ReminderBot(Plugin):
     base_command: Tuple[str, ...]
diff --git a/reminder/reminder.py b/reminder/reminder.py
index fb964c5..291a178 100644
--- a/reminder/reminder.py
+++ b/reminder/reminder.py
@@ -203,17 +203,17 @@ class Reminder(object):
 
         """
         if self.is_agenda:
-            return format_time(self.start_time, user_info)
+            return format_time(self.start_time, user_info=user_info, time_format=self.bot.config['time_format'])
         else:
-            next_run = format_time(self.job.next_run_time, user_info)
+            next_run = format_time(self.job.next_run_time, user_info=user_info, time_format=self.bot.config['time_format'])
             if self.cron_tab:
                 # TODO add languages
                 if USE_CRON_DESCRIPTOR:
                     return f"{ExpressionDescriptor(self.cron_tab, casing_type=CasingTypeEnum.LowerCase)} (`{self.cron_tab}`), next run {next_run}"
                 else:
-                    return f"`{self.cron_tab}`, next run {next_run}"
+                    return f"`{self.cron_tab}`, next run at {next_run}"
             elif self.recur_every:
-                return f"every {self.recur_every}, next run {next_run}"
+                return f"every {self.recur_every}, next run at {next_run}"
             else: # once-off reminders
                 return next_run
 
diff --git a/reminder/util.py b/reminder/util.py
index 78fa00f..50a8101 100644
--- a/reminder/util.py
+++ b/reminder/util.py
@@ -222,13 +222,13 @@ def pluralize(val: int, unit: str) -> str:
         return f"{val} {unit}"
     return f"{val} {unit}s"
 
-def format_time(time: datetime, user_info: UserInfo) -> str:
+def format_time(time: datetime, user_info: UserInfo, time_format: str = "%-I:%M%P %Z on %A, %B %-d %Y") -> str:
     """
     Format time as something readable by humans.
     Args:
         time: datetime to format
-        user_info: contains locale (if using arrow) and timezone
-
+        user_info: contains locale and timezone
+        time_format:
     Returns:
 
     """
@@ -256,8 +256,7 @@ def format_time(time: datetime, user_info: UserInfo) -> str:
                 formatted_time = formatted_time + " ago"
     else:
         formatted_time = time.astimezone(
-            dateparser.utils.get_timezone_from_tz_string(user_info.timezone)).strftime(
-            "at %I:%M%P %Z on %A, %B %d %Y")
+            dateparser.utils.get_timezone_from_tz_string(user_info.timezone)).strftime(time_format)
     return formatted_time
 
 
-- 
GitLab