~protesilaos/tmr

3 2

[PATCH] Strict parsing, support specifying absolute time, e.g., 15:00

Daniel Mendler <mail@daniel-mendler.de>
Details
Message ID
<acce3997-77f1-d1cc-0632-d1abdc648d0a@daniel-mendler.de>
DKIM signature
missing
Download raw message
From 132bd36003ca5e854245b6026d7a8f74765c6060 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <mail@daniel-mendler.de>
Date: Wed, 29 Jun 2022 14:44:32 +0200
Subject: [PATCH] Strict parsing, support specifying absolute time, e.g.,
15:00

(Test: I want to see if this mail appears in the sr.ht patches tab)

---
 tmr.el | 53 +++++++++++++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 22 deletions(-)

diff --git a/tmr.el b/tmr.el
index b56d878..ba62d2f 100644
--- a/tmr.el
+++ b/tmr.el
@@ -142,9 +142,12 @@ Each function must accept a timer as argument."
     ;; enough to be used when starting a timer but also when cancelling
     ;; one: check `tmr-print-message-for-created-timer' and
     ;; `tmr-print-message-for-cancelled-timer'.
-    (format "TMR start %s; end %s; duration %s%s"
+    (format "TMR start %s; end %s; %s %s%s"
             (propertize start 'face 'success)
             (propertize end 'face 'error)
+            (if (string-match-p ":" (tmr--timer-input timer))
+                "until"
+              "duration")
             (tmr--timer-input timer)
             (if description
                 (format " [%s]" (propertize description 'face 'bold))
@@ -189,26 +192,32 @@ optional `tmr--timer-description'."
   "Return a human-readable string representing TIME."
   (format-time-string "%T" time))

-(defun tmr--unit (time)
-  "Determine common time unit for TIME."
-  (cond
-   ((and (stringp time)
-         (string-match-p "[0-9]\\'" time))
-    (let ((time (string-to-number time)))
-      (* time 60)))
-   ((natnump time)
-    (* time 60))
-   (t
-    (let* ((unit (substring time -1))
-           (str (substring time 0 -1))
-           (num (abs (string-to-number str))))
-      (pcase unit
-        ("s" num)
-        ("h" (* num 60 60))
-        ;; This is not needed, of course, but we should not miss a good
-        ;; chance to make some fun of ourselves.
-        ("w" (user-error "TMR Made Ridiculous; append character for
[m]inutes, [h]ours, [s]econds"))
-        (_ (* num 60)))))))
+(defun tmr--unit (now time)
+  "Determine common time unit for TIME given current time NOW."
+  (save-match-data
+    (cond
+     ((natnump time)
+      (* time 60))
+     ((and (stringp time) (string-match-p
"\\`[0-9]+\\(?:\\.[0-9]+\\)?\\'" time))
+      (* (string-to-number time) 60))
+     ((and (stringp time) (string-match
"\\`\\([0-9]+\\):\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?\\'" time))
+      (let ((val (decode-time now)))
+        (setf (decoded-time-hour val) (string-to-number (match-string 1
time))
+              (decoded-time-minute val) (string-to-number (match-string
2 time))
+              (decoded-time-second val) (if (match-end 3)
+                                            (string-to-number
(match-string 3 time))
+                                          0)
+              val (encode-time val))
+        (when (time-less-p val now)
+          (user-error "Time %s is already over" time))
+        (ceiling (float-time (time-subtract val now)))))
+     ((and (stringp time) (string-match
"\\`\\([0-9]+\\(?:\\.[0-9]+\\)?\\)[mhs]\\'" time))
+      (let ((num (string-to-number (match-string 1 time))))
+        (pcase (aref time (1- (length time)))
+          (?s num)
+          (?h (* num 60 60))
+          (?m (* num 60)))))
+     (t (user-error "TMR Made Ridiculous; append character for
[m]inutes, [h]ours, [s]econds")))))

 (defvar tmr--timers nil
   "List of timer objects.
@@ -396,7 +405,7 @@ command `tmr-with-description' instead of this one."
     (tmr--read-duration)
     (when current-prefix-arg (tmr--description-prompt))))
   (let* ((creation-date (current-time))
-         (duration (tmr--unit time))
+         (duration (tmr--unit creation-date time))
          (timer (tmr--timer-create
                  :description description
                  :creation-date creation-date
-- 
2.20.1
Details
Message ID
<875ykjfw6z.fsf@protesilaos.com>
In-Reply-To
<acce3997-77f1-d1cc-0632-d1abdc648d0a@daniel-mendler.de> (view parent)
DKIM signature
missing
Download raw message
> From: Daniel Mendler <mail@daniel-mendler.de>
> Date: Wed, 29 Jun 2022 14:56:40 +0200
>
> (Test: I want to see if this mail appears in the sr.ht patches tab)

I did not check the web UI for this one.  A general note on what I know:
if you send the patch as an attachment or fake it as part of the
message, it is not shown on the website and it does not count as a
"patch" in the relevant tab.

SourceHut has a hardcoded reliance on the git-email-send workflow.  I
would prefer a more flexible approach where "[PATCH]" in the subject
line and/or the presence of a .patch file is enough.

If you choose to use git-email-send, I am okay with it and can apply the
patches just as well.

-- 
Protesilaos Stavrou
https://protesilaos.com
Daniel Mendler <mail@daniel-mendler.de>
Details
Message ID
<96340ec4-5e8b-8e02-b745-05aa805c2677@daniel-mendler.de>
In-Reply-To
<875ykjfw6z.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
On 6/29/22 15:14, Protesilaos Stavrou wrote:
>> From: Daniel Mendler <mail@daniel-mendler.de>
>> Date: Wed, 29 Jun 2022 14:56:40 +0200
>>
>> (Test: I want to see if this mail appears in the sr.ht patches tab)
> 
> I did not check the web UI for this one.  A general note on what I know:
> if you send the patch as an attachment or fake it as part of the
> message, it is not shown on the website and it does not count as a
> "patch" in the relevant tab.
> 
> SourceHut has a hardcoded reliance on the git-email-send workflow.  I
> would prefer a more flexible approach where "[PATCH]" in the subject
> line and/or the presence of a .patch file is enough.
> 
> If you choose to use git-email-send, I am okay with it and can apply the
> patches just as well.

Okay, I see. I guess sr.ht still needs improvements before it can be
used comfortably. It seems to be designed such that it fits only a
single specific work flow, which is favored by the developers. There is
still the issue that links in commit messages are not handled well. Also
Org is not supported as a README format, which is unfortunate for Emacs
development. I wonder how hard it is to add this. Org is a fringe
format, even many of the Emacs maintainers themselves dislike it as
shown by the currently ongoing discussion.

Daniel
Details
Message ID
<87v8sjziad.fsf@protesilaos.com>
In-Reply-To
<96340ec4-5e8b-8e02-b745-05aa805c2677@daniel-mendler.de> (view parent)
DKIM signature
missing
Download raw message
> From: Daniel Mendler <mail@daniel-mendler.de>
> Date: Wed, 29 Jun 2022 15:23:54 +0200
>
> Okay, I see. I guess sr.ht still needs improvements before it can be
> used comfortably. It seems to be designed such that it fits only a
> single specific work flow, which is favored by the developers. There is
> still the issue that links in commit messages are not handled well. Also
> Org is not supported as a README format, which is unfortunate for Emacs
> development. I wonder how hard it is to add this. Org is a fringe
> format, even many of the Emacs maintainers themselves dislike it as
> shown by the currently ongoing discussion.

Indeed, it is not optimal for our purposes.

The other part about the UI I would like to see improvements to is a
link from the git repo to the mailing list and vice-versa.  Now these
need to be documented separately.

-- 
Protesilaos Stavrou
https://protesilaos.com
Reply to thread Export thread (mbox)