From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: How to subtract timestamp in elisp? Date: Sat, 04 Jul 2020 14:54:30 +0200 Message-ID: <87fta730ft.fsf@web.de> References: <87zh8fwn4u.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9939"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:prbHk4Cr3wWrXGG4poJamdqdY8w= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 04 14:56:30 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 1jrhiX-0002Sl-Ic for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 04 Jul 2020 14:56:29 +0200 Original-Received: from localhost ([::1]:41490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrhiW-0005Al-EL for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 04 Jul 2020 08:56:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrhgn-0005AN-UV for help-gnu-emacs@gnu.org; Sat, 04 Jul 2020 08:54:41 -0400 Original-Received: from static.214.254.202.116.clients.your-server.de ([116.202.254.214]:50300 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 1jrhgm-0004j2-4d for help-gnu-emacs@gnu.org; Sat, 04 Jul 2020 08:54:41 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1jrhgh-0000Ka-0F for help-gnu-emacs@gnu.org; Sat, 04 Jul 2020 14:54:35 +0200 X-Injected-Via-Gmane: http://gmane.org/ 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/04 05:08:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 1 X-Spam_score: 0.1 X-Spam_bar: / X-Spam_report: (0.1 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, 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:123494 Archived-At: stardiviner writes: > Is there some hints or suggestion like function name or Emacs library > or package? > Or can convert timestamp into another format then convert back to timestamp. Several possibilities I think. Calc can do it interactively, but I think that's not what you want, you want to do this from Lisp. I didn't find anything that wouldn't require some in-between conversations. Something to start with, as an alternative to Eli's suggestion: `appt-convert-time': Convert hour:min[am/pm] format to minutes from midnight. Obviously, multiply by 60 to get seconds. You may also want to use (defun my-last-midnight (&optional time) (cl-callf or time (current-time)) (apply #'encode-time (apply #'list 0 0 0 (nthcdr 3 (decode-time time))))) if your stamps may span midnight. Use time-add, time-subtract, time-less-p etc for time arithmetic. Accepted input values are time values like the return value of (current-time) but seconds are also allowed where it makes sense. `format-time-string' to convert back to a time stamp like your input is. There are several places in Emacs that implement handling of time strings somehow (Calc, org, calendar, diary, appt), but none offers what you want out of the box completely AFAIK. Michael.