emacs-tangents
[Top][All Lists]
Advanced

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

Re: 2022-11-14 Emacs news


From: Emanuel Berg
Subject: Re: 2022-11-14 Emacs news
Date: Tue, 15 Nov 2022 05:39:28 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Sacha Chua wrote:

> Maybe next week, we'll see!

I think it should happen today, now even.

It's about time.

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/today.el

(defun eat-and-beat (re data)
  (save-excursion
    (if (looking-at re)
        (replace-match data)
      (insert data) )
    (save-buffer) ))

(defun today ()
  (interactive)
  (let ((date-re "[[:digit:]]\\{4\\}-[[:digit:]]\\{2\\}-[[:digit:]]\\{2\\}")
        (date (format-time-string "%F")) )
    (eat-and-beat date-re date) ))

(defun now ()
  (interactive)
  (let ((time-re "[[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}")
        (time (format-time-string "%R")) )
    (eat-and-beat time-re time) ))

(provide 'today)

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/time-cmp.el

(require 'cl-lib)

(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 (d1 d2)
  (let*((sep     "-")
        (d1-data (cl-map 'list #'string-to-number (split-string d1 sep)))
        (d2-data (cl-map 'list #'string-to-number (split-string d2 sep)))
        (y1      (car   d1-data))
        (m1      (cadr  d1-data))
        (d1      (caddr d1-data))
        (y2      (car   d2-data))
        (m2      (cadr  d2-data))
        (d2      (caddr d2-data)) )
    (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]

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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