[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Elisp - Function returning a list
From: |
Jean Louis |
Subject: |
Re: Elisp - Function returning a list |
Date: |
Wed, 16 Dec 2020 08:33:06 +0300 |
User-agent: |
Mutt/2.0 (3d08634) (2020-11-07) |
* Yuri Khan <yuri.v.khan@gmail.com> [2020-12-16 07:39]:
> On Wed, 16 Dec 2020 at 11:30, <steve-humphreys@gmx.com> wrote:
> >
> > For me 800 is 8 O'Clock
>
> You cannot just do decimal arithmetics on times written in that format.
>
> Start: 800 End: 1100 Skip: 45
> Expected: 800 845 930 1015 1100
> Actual: 800 845 890 935 980 1025 1070
I am using external tools that have features built-in, PostgreSQL
database has it.
(defun my-time-range (time-start add-hours interval-in-minutes)
(interactive "MBegin time by format HH:MM: \nMFor how many hours later?
\nMInterval in minutes: ")
(let* ((sql (format "SELECT to_char(t.hour::timestamp,'HH:MI') FROM
generate_series('2020-01-01 %s:00'::timestamp, '2020-01-01 %s:00'::timestamp +
interval '%s hours', '%s minutes'::interval) as t(hour);" time-start
time-start add-hours interval-in-minutes))
(command (format "psql -tc \"%s\"" sql)))
(insert (shell-command-to-string command))))
With: 10:00 and 20 hours later with interval of 35 minutes, result is:
10:00
10:35
11:10
11:45
12:20
12:55
01:30
02:05
02:40
03:15
03:50
04:25
05:00
05:35
06:10
06:45
07:20
07:55
08:30
09:05
09:40
10:15
10:50
11:25
12:00
12:35
01:10
01:45
02:20
02:55
03:30
04:05
04:40
05:15
05:50
To make a list from external command, then:
(defun my-time-range (time-start add-hours interval-in-minutes)
(interactive "MBegin time by format HH:MM: \nMFor how many hours later?
\nMInterval in minutes: ")
(let* ((sql (format "SELECT to_char(t.hour::timestamp,'HH:MI') FROM
generate_series('2020-01-01 %s:00'::timestamp, '2020-01-01 %s:00'::timestamp +
interval '%s hours', '%s minutes'::interval) as t(hour);" time-start
time-start add-hours interval-in-minutes))
(command (format "psql -qtc \"%s\"" sql))
(result (shell-command-to-string command))
(list (split-string result "\n"))
(list (mapcar #'string-trim list))
(list (delete-if #'seq-empty-p list)))
list))
(my-time-range "10:00" "20" "35") => ("10:00" "10:35" "11:10" "11:45" "12:20"
"12:55" "01:30" "02:05" "02:40" "03:15" "03:50" "04:25" "05:00" "05:35" "06:10"
"06:45" "07:20" "07:55" "08:30" "09:05" "09:40" "10:15" "10:50" "11:25" "12:00"
"12:35" "01:10" "01:45" "02:20" "02:55" "03:30" "04:05" "04:40" "05:15" "05:50")
Maybe such Emacs package does exist but if little fiddling with
the external tool helps me to get the range, then I use external
tool.
Jean
- Re: let, let*, oh, why [was: Elisp - Function returning a list], (continued)
- Re: let, let*, oh, why [was: Elisp - Function returning a list], Jean Louis, 2020/12/21
- Re: let, let*, oh, why [was: Elisp - Function returning a list], Emanuel Berg, 2020/12/21
- Re: let, let*, oh, why [was: Elisp - Function returning a list], tomas, 2020/12/21
- RE: let, let*, oh, why [was: Elisp - Function returning a list], Drew Adams, 2020/12/21
- Re: let, let*, oh, why [was: Elisp - Function returning a list], tomas, 2020/12/21
Re: Elisp - Function returning a list, steve-humphreys, 2020/12/15
Re: Elisp - Function returning a list, steve-humphreys, 2020/12/16
Re: Elisp - Function returning a list,
Jean Louis <=
Re: Elisp - Function returning a list, Emanuel Berg, 2020/12/16
Re: Elisp - Function returning a sequence of times, Jean Louis, 2020/12/16
Re: Elisp - Function returning a sequence of times, steve-humphreys, 2020/12/16
Re: Elisp - Function returning a sequence of times, Joost Kremers, 2020/12/16
Re: Elisp - Function returning a sequence of times, steve-humphreys, 2020/12/16
Re: Elisp - Function returning a sequence of times, Michael Heerdegen, 2020/12/16
Re: Elisp - Function returning a list, Emanuel Berg, 2020/12/15