Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ClaireSoftware/a9ad475b03c06d398ea203c65934e95c to your computer and use it in GitHub Desktop.
Save ClaireSoftware/a9ad475b03c06d398ea203c65934e95c to your computer and use it in GitHub Desktop.
Emacs Lisp Time Ranges
# How to get time ranges with emacs lisp
```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