unofficial mirror of emacs-tangents@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: emacs-tangents@gnu.org
Subject: Re: 2022-11-14 Emacs news
Date: Tue, 15 Nov 2022 05:39:28 +0100	[thread overview]
Message-ID: <87o7t8q1a7.fsf@dataswamp.org> (raw)
In-Reply-To: CAJGZZeK-7O_hzeFJgwFrs3v9xttairuQv71DsLB0aJjAHVLBCQ@mail.gmail.com

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	other threads:[~2022-11-15  4:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14 16:02 2022-11-14 Emacs news Sacha Chua
2022-11-15  0:29 ` Emanuel Berg
2022-11-15  3:53   ` Sacha Chua
2022-11-15  4:39     ` Emanuel Berg [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87o7t8q1a7.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=emacs-tangents@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).