notes from /dev/null

by Charles Choi 최민수


08 Apr 2026

Computing Days Until with Emacs

A recent Mastodon post showing the days until the next U.S. election got me to wonder, “how can I compute that in Emacs?” Turns out, this is trivial with the Org mode function org-time-stamp-to-now doing the timestamp computation for you.

We can wrap org-time-stamp-to-now in an internal function cc/--days-until that generates a formatted string of the days until a target date.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
(defun cc/--days-until (target &optional template)
  "Formatted string of days until TARGET.

- TARGET: date string that conforms to `parse-time-string'.
- TEMPLATE : format string that includes ‘%d’ specifier.

If TEMPLATE is nil, then a predefined format string will be
used."
  (let* ((template (if template
                       template
                     (concat "%d days until " target)))
         (days (org-time-stamp-to-now target))
         (msg (format template days)))
    msg))

From there we can then start defining commands that use cc/--days-until. The command cc/days-until shown below will prompt you with a date picker to enter a date. Note that you can enter a date value (e.g. “Dec 25, 2026”) in the mini-buffer prompt for org-read-date.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(defun cc/days-until (arg)
  "Prompt user for date and show days until in the mini-buffer.

Use `org-read-date' to compute days until to display in the mini-buffer.

If prefix ARG is non-nil, then the computed result is stored in the
 `kill-ring'."
  (interactive "P")
  (let* ((target (org-read-date))
         (msg (cc/--days-until target)))
    (if arg
        (kill-new msg))
    (message msg)))

Going back to the original motivator for this post, here’s an implementation of days until the next two major U.S. election dates with the command cc/days-until-voting.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
(defun cc/days-until-voting (arg)
  "Days until U.S. elections in 2026 and 2028.

If prefix ARG is non-nil, then the computed result is stored in the
 `kill-ring'."
  (interactive "P")
  (let* ((midterms (cc/--days-until "2026-11-03" "%d days until 2026 midterms"))
         (election (cc/--days-until "2028-11-07" "%d days until 2028 presidential election"))
         (msg (format "%s, %s" midterms election)))
    (if arg
        (kill-new msg))
    (message msg)))

The result of M-x cc/days-until-voting as of 8 April 2026 is:

209 days until 2026 midterms, 944 days until 2028 presidential election

It’s so human to want to know how long it’s going to take. Feel free to build your own countdown clocks using the code above. May your journey to whatever you plan be a happy one!

emacs   org mode

Past Articles

7
APR
2026

Calming Mouse Interaction in Dired

Single click to open a file in Dired is too twitchy. This post shows how to change it.

read more
30
MAR
2026

Announcing Anju

Announcing Anju, a project to align mouse interactions in Emacs with contemporary (circa 2026) expectations. Now available on MELPA.

read more
3
MAR
2026

Casual now available on NonGNU ELPA

Casual is now available on NonGNU ELPA.

read more
19
FEB
2026

Announcing Casual Org

At long last, announcing Casual support for Org Mode.

read more
10
FEB
2026

Deburring Emacs Imenu GUI Configuration

A bit of tuning to get Imenu GUI configuration working with any derived mode from prog-mode.

read more
7
FEB
2026

Using Casual to work with Emacs Registers, Rectangles, and Windows

Use Casual to effectively use Emacs registers, rectangles, and windows on the regular.

read more
26
JAN
2026

Getting Eshell nth History to Work

Out of the box, Eshell nth history recall is disabled. Here’s how to turn it on.

read more
22
JAN
2026

Announcing Casual EWW

Announcing Casual support for EWW, a web browser within Emacs.

read more
6
JAN
2026

Announcing Casual HTML & CSS

Announcing Casual support for the HTML and CSS editing modes in Emacs.

read more

Page 1 / 18   >

 

AboutMastodonBlueskyGitHub

Feeds & Tags
Get Scrim for macOSGet Captee for macOS

Powered by Pelican