From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: stardiviner Newsgroups: gmane.emacs.help Subject: [SOLVED] Re: How to subtract timestamp in elisp? Date: Sun, 05 Jul 2020 11:04:16 +0800 Message-ID: <87y2nyd5n3.fsf@gmail.com> References: <87zh8fwn4u.fsf@gmail.com> Reply-To: numbchild@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17516"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4; emacs 28.0.50 Cc: Emacs Help To: Dmitry Alexandrov Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 05 05:05:23 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 1jruy3-0004T6-0T for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 05 Jul 2020 05:05:23 +0200 Original-Received: from localhost ([::1]:40248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jruy2-0002no-2z for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 04 Jul 2020 23:05:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jruxg-0002nX-Qi for help-gnu-emacs@gnu.org; Sat, 04 Jul 2020 23:05:00 -0400 Original-Received: from [183.249.139.74] (port=10861 helo=localhost) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jruxe-0001ni-Tf for help-gnu-emacs@gnu.org; Sat, 04 Jul 2020 23:05:00 -0400 Original-Received: by localhost (Postfix, from userid 1000) id 813D22415B7; Sun, 5 Jul 2020 11:04:16 +0800 (CST) In-reply-to: X-Host-Lookup-Failed: Reverse DNS lookup failed for 183.249.139.74 (deferred) Received-SPF: softfail client-ip=183.249.139.74; envelope-from=numbchild@gmail.com; helo=localhost X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/04 23:04:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 63 X-Spam_score: 6.3 X-Spam_bar: ++++++ X-Spam_report: (6.3 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, FSL_HELO_NON_FQDN_1=0.001, HELO_LOCALHOST=3.828, NML_ADSP_CUSTOM_MED=0.9, RDNS_NONE=0.793, SPF_SOFTFAIL=0.665, SPOOFED_FREEMAIL_NO_RDNS=1 autolearn=_AUTOLEARN X-Spam_action: reject 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:123502 Archived-At: Dmitry Alexandrov writes: > stardiviner wrote: >> I hope a function can subtract two timestamps: >> >> 00:12:35 - 00:10:45 =3D 00:01:50 >> >> Is there some hints or suggestion like function name or Emacs library or= package? > >> Or Linux command is acceptable. I can write a function to execute shell = command then parse the result. > > OMG! Since when that started to require anything but arithmetics? > > (defun timestamp-interval (a b) > (cl-flet* ((hms->s (h m s) (+ (* 3600 h) > (* 60 m) > s)) > (s->hms (s) (let* ((h (/ s 3600)) > (s (% s 3600)) > (m (/ s 60)) > (s (% s 60))) > (list h m s))) > (timestamp->s (string) (apply #'hms->s > (mapcar #'string-to-number > (split-string string = ":")))) > (s->timestamp (s) (apply #'format "%s%02d:%02d:%02d" > (if (> 0 s) "-" "") (s->hms (abs s= ))))) > (s->timestamp (- (timestamp->s a) (timestamp->s b))))) >=20=09 > (timestamp-interval "00:12:35" "00:10:45") > ;; =3D> "00:01:50" > > (Not tested.) > Dmitry: This is really great. I thought to use `split-string` too to parse timestam= p. My thought was to use existing API if exist when I compose this email. But implement a function to dealing with this is great too. Thanks for your hel= p. And of course Eli and Michael too. > P. S. Sending mail =E2=80=98From: =E2=80=A6@gmail.com=E2=80=99 right from= your home machine is a best > way to send it straight to junk folder. ;-) Use smtp.gmail.com. I used to realized my email always go into Gmail junk, can't find out the reason. I guess you just solved my long time issue. I'm using Emacs mu4e package. I will Google how to use SMTP server in mu4e. Thanks again. --=20 [ stardiviner ] I try to make every word tell the meaning that I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3