Created
October 6, 2019 23:56
-
-
Save ClaireSoftware/a9ad475b03c06d398ea203c65934e95c to your computer and use it in GitHub Desktop.
Emacs Lisp Time Ranges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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