From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Alexandrov Newsgroups: gmane.emacs.help Subject: Re: How to subtract timestamp in elisp? Date: Sun, 05 Jul 2020 00:11:25 +0300 Message-ID: References: <87zh8fwn4u.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4066"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Emacs Help To: numbchild@gmail.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 04 23:13:19 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 1jrpTK-0000w5-PN for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 04 Jul 2020 23:13:18 +0200 Original-Received: from localhost ([::1]:46744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrpSI-00063D-0B for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 04 Jul 2020 17:12:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrpRh-000637-Ut for help-gnu-emacs@gnu.org; Sat, 04 Jul 2020 17:11:37 -0400 Original-Received: from relay-2.mailobj.net ([213.182.54.5]:59091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrpRc-00009u-ER for help-gnu-emacs@gnu.org; Sat, 04 Jul 2020 17:11:37 -0400 Original-Received: from v-1c.localdomain (unknown [192.168.90.161]) by relay-2.mailobj.net (Postfix) with SMTP id BF45C12B8; Sat, 4 Jul 2020 23:11:28 +0200 (CEST) Original-Received: by mail-1.net-c.com [213.182.54.15] with ESMTP Sat, 4 Jul 2020 23:11:28 +0200 (CEST) X-EA-Auth: pkmg9kH8WRaJezYKDy9Y5ZE3tzBoyH70tkK7zwCPStaVhDrZmHmVTTMfCo2rQmZVsaxgzJ45Z02Jfgu4zelrGpoqRf/DwENB In-Reply-To: <87zh8fwn4u.fsf@gmail.com> (stardiviner's message of "Sat, 04 Jul 2020 19:11:29 +0800") Received-SPF: pass client-ip=213.182.54.5; envelope-from=dag@gnui.org; helo=relay-2.mailobj.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/04 17:11:29 X-ACL-Warn: Detected OS = Linux 3.1-3.10 X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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:123497 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 c= ommand 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))))) =09 (timestamp-interval "00:12:35" "00:10:45") ;; =3D> "00:01:50" (Not tested.) P. S. Sending mail =E2=80=98From: =E2=80=A6@gmail.com=E2=80=99 right from y= our home machine is a best way to send it straight to junk folder. ;-) Use= smtp.gmail.com. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iIMEARYIACsWIQRSX35grYEsI2F1K7TIsPhUjufz5wUCXwDwfg0cZGFnQGdudWku b3JnAAoJEMiw+FSO5/Pn0jAA/1xczbcV0RoLGG8IOYv4yXRYbEQZINvVJoT1yBuZ jYx+AP0YLf23PCzAD8+jn0PjiWyFbNZfl5JxIq6XJr7oxuXLCA== =PzxC -----END PGP SIGNATURE----- --=-=-=--