;;; -*- 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 (y1 m1 d1 h1 min1 s1 y2 m2 d2 h2 min2 s2) (let*((s-then (float-time (encode-time s1 min1 h1 d1 m1 y1))) (s-now (float-time (encode-time s2 min2 h2 d2 m2 y2))) (s-diff (- s-now s-then)) ) (format-seconds "%yy %dd %hh %mm %ss" s-diff))) ;; DNC: ;; (time-between-times 1958 4 13 1958 8 30) ; Tahiti Nui 2 -> 3, 139 days (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 (defun dope (boxes pills dose &optional from) (interactive "nboxes: \nnpills/box: \nnpills/day: ") (let*((days (/ (* boxes pills) dose)) (done (time-add (when from (date-to-time (concat from "T00:00+01:00")) ) (days-to-time (1- days)) )) (str (format-time-string "%F" done)) (more (format-time-string "%F" (time-add done (days-to-time -10)))) ) (insert (format "%s [%s] %s" ; don't change (or from (format-time-string "%F")) more str) )))