From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: How to subtract timestamp in elisp? Date: Sun, 05 Jul 2020 15:30:36 +0200 Message-ID: <87fta6m6mb.fsf@ebih.ebihd> References: <87zh8fwn4u.fsf@gmail.com> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22962"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:ivGz373Mi5Yhc8Nmmnm07665+y0= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 05 15:31:34 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 1js4k1-0005pc-NT for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 05 Jul 2020 15:31:33 +0200 Original-Received: from localhost ([::1]:59984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1js4k0-0007pF-Lp for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 05 Jul 2020 09:31:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1js4jI-0007nj-BG for help-gnu-emacs@gnu.org; Sun, 05 Jul 2020 09:30:48 -0400 Original-Received: from static.214.254.202.116.clients.your-server.de ([116.202.254.214]:58092 helo=ciao.gmane.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1js4jG-00026I-8S for help-gnu-emacs@gnu.org; Sun, 05 Jul 2020 09:30:48 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1js4jB-0004xD-Vo for help-gnu-emacs@gnu.org; Sun, 05 Jul 2020 15:30:41 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/05 09:30:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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:123503 Archived-At: stardiviner wrote: > I'm find an Elisp solution to subtract timestamps > like "00:12:35". > > I hope a function can subtract two timestamps: > > 00:12:35 - 00:10:45 = 00:01:50 Here are there functions that might be what you look for, or be interesting to check out at least: ;;; -*- lexical-binding: t -*- ;;; ;;; this file: ;;; http://user.it.uu.se/~embe8573/emacs-init/time-cmp.el ;;; https://dataswamp.org/~incal/emacs-init/time-cmp.el (defun wall-clock-time (h1 m1 s1 h2 m2 s2) (let*((d 08) ; arbitrary day to use below, any would do (m 05) ; actually something cool happened that day (y 1978) ; in the history of climbing (total-seconds-1 (float-time (encode-time s1 m1 h1 d m y))) (total-seconds-2 (float-time (encode-time s2 m2 h2 d m y))) (s-diff (- total-seconds-2 total-seconds-1)) ) (format-seconds "%.2h:%.2m:%.2s" s-diff) )) (defalias 'wct #'wall-clock-time) ;; (wct 09 35 10 23 00 00) ; 13:24:50 ;; (wct 09 35 10 09 35 20) ; 00:00:10 (defun time-between-times (year1 month1 day1 year2 month2 day2) (let*((seconds-then (float-time (encode-time 0 0 0 day1 month1 year1))) (seconds-now (float-time (encode-time 0 0 0 day2 month2 year2))) (seconds-diff (- seconds-now seconds-then)) ) (format-seconds "%yy %dd" seconds-diff))) ;; (time-between-times 1958 4 13 1958 8 30) ; Tahiti Nui 2 -> 3, ;; ; i.e. 0y 139d (defun get-time-since (year month day) (interactive "nyear: \nnmonth: \nnday: ") (message "%s" (format-seconds "%yy %dd" (float-time (time-since (encode-time 0 0 0 day month year)) )))) ;; (get-time-since 2011 09 27) ; 8y 228d @ 2020-05-10 -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal