From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Elisp - Function returning a list Date: Wed, 16 Dec 2020 08:33:06 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40866"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0 (3d08634) (2020-11-07) Cc: Help Gnu Emacs , steve-humphreys@gmx.com To: Yuri Khan Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 16 06:38:22 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kpPW1-000AXU-JC for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Dec 2020 06:38:21 +0100 Original-Received: from localhost ([::1]:46140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpPW0-0005C1-Im for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Dec 2020 00:38:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpPT7-00036d-9u for help-gnu-emacs@gnu.org; Wed, 16 Dec 2020 00:35:22 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:56755) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpPT4-0003iL-PO for help-gnu-emacs@gnu.org; Wed, 16 Dec 2020 00:35:20 -0500 Original-Received: from localhost ([::ffff:197.157.0.58]) (AUTH: PLAIN securesender, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000001DFF7.000000005FD99C94.000029F8; Tue, 15 Dec 2020 22:35:15 -0700 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: 29 X-Spam_score: 2.9 X-Spam_bar: ++ X-Spam_report: (2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_SBL_CSS=3.335, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:126408 Archived-At: * Yuri Khan [2020-12-16 07:39]: > On Wed, 16 Dec 2020 at 11:30, 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