emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Gustavo Barros <gusbrs.2016@gmail.com>
To: Bastien <bzg@gnu.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: A small idea to simplify (further) time input in the date/time prompt
Date: Wed, 03 Jun 2020 10:14:26 -0300	[thread overview]
Message-ID: <87a71kqojx.fsf@gmail.com> (raw)
In-Reply-To: <87a71lacw6.fsf@bzg.fr>

[-- Attachment #1: Type: text/plain, Size: 2202 bytes --]

Hi Bastien,

On Tue, Jun 02 2020, Bastien wrote:

> Hi Gustavo,
>
> I like this idea, thanks for proposing it.  We are in feature freeze
> for core features, so we have time to work on this for Org 9.5.
>

[...]

> Would you agree?  Would you like to work on this change?

Well, I did give it a shot.  And, as it turns out, this might be 
manageable within my limitations.

A preliminary patch is attached, for comments.

I took here the stance of following the same treatment which is given to 
am/pm times, and of using the letter "h" as sole main identifier.  In 
particular, standard "HH:MM" times take precedence, as is the case for 
am/pm times.  And duration specification with numbers only are presumed 
to be hours, which was already the case, the patch does not introduce 
any changes here.  The input will match for this format for "number h 
2-digit-number", where either the hour or the minutes, but not both, can 
be omitted and, if so, is presumed to be zero.  24h format is also 
presumed.

With it, some example inputs/outputs for time in the date/time prompt:

| input     |      output |
|-----------+-------------|
| 9h        |       09:00 |
| h45       |       00:45 |
| 21h       |       21:00 |
| 9h-10h    | 09:00-10:00 |
| 9h--10h30 | 09:00-10:30 |
| 18h30+h30 | 18:30-19:00 |
| 18h30+1   | 18:30-19:30 |
| 18h30+1h  | 18:30-19:30 |

And some sanity checks:

| input     | output               | Observation 
  |
|-----------+----------------------+-------------------------------------------|
| 10:00 9h  | 10:00                | by design, as for am/pm times 
  |
| 10am 9h   | 10:00                | expected from coming after am/pm 
  handling |
| 10:00-11h | 10:00-11:00          | 
  |
| 10h-11:00 | no match             | am/pm also does not match here 
  |
| +9h       | no match             | 
  |
| -9h       | no match             | 
   |
| h         | no match             | 
  |
| 10h+h     | no match             | 
  |
| h5        | no match             | 
  |
| 10h70     | no match             | 
  |
| 29h       | 2020-06-04 Thu 05:00 | makes sense, same as for 29:00 
  |
| 30h       | no match             | as per the regexp 
  |

WDYT?

Best,
Gustavo.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-date-time-prompt-Provide-support-for-HHhMM-time-inpu.patch --]
[-- Type: text/x-diff, Size: 2075 bytes --]

From 02829c7771a1f7a0c00d607a924fb8f56d2f3dd6 Mon Sep 17 00:00:00 2001
From: Gustavo Barros <gusbrs.2016@gmail.com>
Date: Wed, 3 Jun 2020 08:57:53 -0300
Subject: [PATCH] date/time prompt: Provide support for HHhMM time input

* lisp/org.el (org-read-date-analyze): Add support for HHhMM time
input, in similar way as for am/pm times.
* doc/org-manual.org (The date/time prompt): Add example to illustrate
the feature.

TINYCHANGE
---
 doc/org-manual.org |  1 +
 lisp/org.el        | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 92252179b..bfd2aea1f 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -6017,6 +6017,7 @@ dash(es) as the separator in the former case and use =+= as the
 separator in the latter case, e.g.:
 
 | =11am-1:15pm=  | \rArr{} 11:00-13:15   |
+| =11h-13h15=    | \rArr{} same as above |
 | =11am--1:15pm= | \rArr{} same as above |
 | =11am+2:15=    | \rArr{} same as above |
 
diff --git a/lisp/org.el b/lisp/org.el
index b869e12e1..8333e1a5a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -13981,6 +13981,19 @@ user."
 	       (setq ans (replace-match (format "%02d:%02d" hour minute)
 					t t ans))))
 
+    ;; Help matching HHhMM times, similarly as for am/pm times.
+    (cl-loop for i from 1 to 2 do	; twice, for end time as well
+	     (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans))
+			(string-match "\\(?:\\(?1:[012]?[0-9]\\)?h\\(?2:[0-5][0-9]\\)\\)\\|\\(?:\\(?1:[012]?[0-9]\\)h\\(?2:[0-5][0-9]\\)?\\)\\>" ans))
+	       (setq hour (if (match-end 1)
+				(string-to-number (match-string 1 ans))
+			      0)
+		     minute (if (match-end 2)
+				(string-to-number (match-string 2 ans))
+			      0))
+	       (setq ans (replace-match (format "%02d:%02d" hour minute)
+					t t ans))))
+
     ;; Check if a time range is given as a duration
     (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans)
       (setq hour (string-to-number (match-string 1 ans))
-- 
2.17.1


  parent reply	other threads:[~2020-06-03 13:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 12:29 A small idea to simplify (further) time input in the date/time prompt Gustavo Barros
2020-05-21 12:44 ` Gustavo Barros
2020-05-21 12:46 ` Eric S Fraga
2020-05-21 15:52   ` Robert Horn
2020-05-21 16:46     ` Detlef Steuer
2020-05-21 16:49     ` Gustavo Barros
2020-05-21 20:09       ` Robert Horn
2020-06-02 12:08 ` Bastien
2020-06-02 12:58   ` Gustavo Barros
2020-06-03 13:14   ` Gustavo Barros [this message]
2020-10-06 10:42     ` Gustavo Barros
2021-05-01 15:40     ` Bastien
2021-05-01 20:15       ` Gustavo Barros
2020-06-02 13:58 ` stardiviner
2020-06-02 14:14   ` Gustavo Barros
2020-06-02 14:42     ` stardiviner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a71kqojx.fsf@gmail.com \
    --to=gusbrs.2016@gmail.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).