all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: stardiviner <numbchild@gmail.com>
To: Dmitry Alexandrov <dag@gnui.org>
Cc: Emacs Help <help-gnu-emacs@gnu.org>
Subject: [SOLVED] Re: How to subtract timestamp in elisp?
Date: Sun, 05 Jul 2020 11:04:16 +0800	[thread overview]
Message-ID: <87y2nyd5n3.fsf@gmail.com> (raw)
In-Reply-To: <zh8f6l4y.dag@gnui.org>


Dmitry Alexandrov <dag@gnui.org> writes:

> stardiviner <numbchild@gmail.com> wrote:
>> I hope a function can subtract two timestamps:
>>
>>     00:12:35 - 00:10:45 = 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)))))
> 	
> 	(timestamp-interval "00:12:35" "00:10:45")
> 	;; => "00:01:50"
>
> (Not tested.)
>

Dmitry:

This is really great. I thought to use `split-string` too to parse timestamp. 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 help.
And of course Eli and Michael too.

> P. S. Sending mail ‘From: …@gmail.com’ 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.

-- 
[ 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



  reply	other threads:[~2020-07-05  3:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-04 11:11 How to subtract timestamp in elisp? stardiviner
2020-07-04 11:39 ` Eli Zaretskii
2020-07-04 12:54 ` Michael Heerdegen
2020-07-04 21:17   ` Dmitry Alexandrov
2020-07-04 21:11 ` Dmitry Alexandrov
2020-07-05  3:04   ` stardiviner [this message]
2020-07-06  2:48     ` mu4e: configuring SMTP (was: [SOLVED] Re: How to subtract timestamp in elisp?) Dmitry Alexandrov
2020-07-05 13:30 ` How to subtract timestamp in elisp? Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-06  1:43   ` stardiviner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y2nyd5n3.fsf@gmail.com \
    --to=numbchild@gmail.com \
    --cc=dag@gnui.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.