Skip to content

Instantly share code, notes, and snippets.

@ClaireSoftware
Created October 6, 2019 23:56
Show Gist options
  • Save ClaireSoftware/d8f03a1f2ab0205cd63fcf06c5131597 to your computer and use it in GitHub Desktop.
Save ClaireSoftware/d8f03a1f2ab0205cd63fcf06c5131597 to your computer and use it in GitHub Desktop.
How to get time ranges with emacs lisp

How to get time ranges with emacs lisp

(defun time-in-range-p (lower time higher)
  (and (time-less-p lower time) (time-less-p time higher)))
(defun hm-to-time (hours minutes)
  (apply 'encode-time 0 minutes hours (subseq (decode-time) 3 6)))

Example code:

(cond ((time-in-range-p (hm-to-time 7 0) (current-time) (hm-to-time 10 30)) 'breakfast)
      ((time-in-range-p (hm-to-time 10 45) (current-time) (hm-to-time 14 30)) 'lunch)
      ((time-in-range-p (hm-to-time 16 45) (current-time) (hm-to-time 20 00)) 'dinner))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment