* calculating relative time until a day of week
@ 2024-07-06 20:38 Christopher Howard
2024-07-07 5:10 ` tomas
2024-07-08 1:05 ` Michael Heerdegen via Users list for the GNU Emacs text editor
0 siblings, 2 replies; 4+ messages in thread
From: Christopher Howard @ 2024-07-06 20:38 UTC (permalink / raw
To: Help Gnu Emacs Mailing List
Hi, I want to make an Emacs timer that runs a command once a week, every Tuesday at 4am. I could do this with run-at-time and a relative time, but I would need to calculate how many seconds until Tuesday 4am. Is there an easy way to calcuate that?
--
📛 Christopher Howard
🚀 gemini://gem.librehacker.com
🌐 http://gem.librehacker.com
בראשית ברא אלהים את השמים ואת הארץ
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: calculating relative time until a day of week
2024-07-06 20:38 calculating relative time until a day of week Christopher Howard
@ 2024-07-07 5:10 ` tomas
2024-07-08 1:05 ` Michael Heerdegen via Users list for the GNU Emacs text editor
1 sibling, 0 replies; 4+ messages in thread
From: tomas @ 2024-07-07 5:10 UTC (permalink / raw
To: Christopher Howard; +Cc: Help Gnu Emacs Mailing List
[-- Attachment #1: Type: text/plain, Size: 799 bytes --]
On Sat, Jul 06, 2024 at 12:38:47PM -0800, Christopher Howard wrote:
> Hi, I want to make an Emacs timer that runs a command once a week, every Tuesday at 4am. I could do this with run-at-time and a relative time, but I would need to calculate how many seconds until Tuesday 4am. Is there an easy way to calcuate that?
(time-subtract (date-to-time "2024-11-13T10:22:00+0100")
(current-time))
Note that Emacs's internal time representation is "abstract" -- you
shouldn't rely too much on its details. But you have a set of functions
to operate on it and to move from/to human readable representations.
See all the chapters on time in Elisp's "System Interface" section,
especially "42.8 Parsing and Formatting Times" and "42.10 Time
Calculations".
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: calculating relative time until a day of week
2024-07-06 20:38 calculating relative time until a day of week Christopher Howard
2024-07-07 5:10 ` tomas
@ 2024-07-08 1:05 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-07-08 18:00 ` Emanuel Berg
1 sibling, 1 reply; 4+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-07-08 1:05 UTC (permalink / raw
To: help-gnu-emacs
Christopher Howard <christopher@librehacker.com> writes:
> Hi, I want to make an Emacs timer that runs a command once a week,
> every Tuesday at 4am. I could do this with run-at-time and a relative
> time, but I would need to calculate how many seconds until Tuesday
> 4am. Is there an easy way to calcuate that?
Depending on what that command is for, an answer might be "Use diary and
appointments" Or org-mode.
Michael.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: calculating relative time until a day of week
2024-07-08 1:05 ` Michael Heerdegen via Users list for the GNU Emacs text editor
@ 2024-07-08 18:00 ` Emanuel Berg
0 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2024-07-08 18:00 UTC (permalink / raw
To: help-gnu-emacs
Michael Heerdegen via Users list for the GNU Emacs text editor wrote:
>> Hi, I want to make an Emacs timer that runs a command once
>> a week, every Tuesday at 4am. I could do this with
>> run-at-time and a relative time, but I would need to
>> calculate how many seconds until Tuesday 4am. Is there an
>> easy way to calcuate that?
>
> Depending on what that command is for, an answer might be
> "Use diary and appointments" Or org-mode.
Here is a bunch of time stuff, maybe some of it can be
modified for that purpose.
;;; -*- lexical-binding: t -*-
;;
;; this file:
;; https://dataswamp.org/~incal/emacs-init/time-cmp.el
(require 'cl-lib)
(require 'pcase)
(defun wall-clock-time (h1 m1 s1 h2 m2 s2)
(let*((y 1978) (m 05) (d 08) ; arbitrary date, 1978-05-08
(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
(defun days (y1 m1 d1 y2 m2 d2)
(let*((then (float-time (encode-time 0 0 0 d1 m1 y1)))
(now (float-time (encode-time 0 0 0 d2 m2 y2)))
(diff (- now then)) )
(string-to-number (format-seconds "%d" diff)) ))
;; (days 1958 04 13 1958 08 30) ; 139 days between Tahiti Nui 2 & 3
(defun days-date (date1 date2)
(pcase-let*(
(sep "-")
(`(,y1 ,m1 ,d1) (cl-map 'list #'string-to-number (split-string date1 sep)))
(`(,y2 ,m2 ,d2) (cl-map 'list #'string-to-number (split-string date2 sep))) )
(days y1 m1 d1 y2 m2 d2) ))
;; (days-date "2021-03-19" "2021-04-20") ; 31
;; (days-date "1964-07-26" "2021-03-22") ; 20 693
(defun get-time-since (y m d)
(interactive "nyear: \nnmonth: \nnday: ")
(message "%s"
(format-seconds "%yy %dd"
(float-time
(time-since (encode-time 0 0 0 d m y)) ))))
;; (get-time-since 2011 09 27) ; 10y 172d [2022-03-15]
(defun days-since (y m d)
(string-to-number
(format-seconds "%d"
(float-time (time-since (encode-time 0 0 0 d m y))) )))
;; (days-since 1 1 1) ; 738 228 days from 0001-01-01 [2022-03-15]
(provide 'time-cmp)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-08 18:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-06 20:38 calculating relative time until a day of week Christopher Howard
2024-07-07 5:10 ` tomas
2024-07-08 1:05 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-07-08 18:00 ` Emanuel Berg
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.