[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to subtract timestamp in elisp?

From: Michael Heerdegen
Subject: Re: How to subtract timestamp in elisp?
Date: Sat, 04 Jul 2020 14:54:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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

`appt-convert-time': Convert hour:min[am/pm] format to minutes from

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]