Skip to content

Commit

Permalink
FIX: using encode-time and decode-time for run-at-time + bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
guidoschmidt committed Jul 8, 2018
1 parent 32874ae commit 9894361
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions circadian.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Guido Schmidt
;; Maintainer: Guido Schmidt <git@guidoschmidt.cc>
;; URL: https://github.com/GuidoSchmidt/circadian
;; Version: 0.3.1
;; Version: 0.3.2
;; Keywords: themes
;; Package-Requires: ((emacs "24.4"))

Expand Down Expand Up @@ -71,15 +71,24 @@
(run-hook-with-args 'circadian-after-load-theme-hook theme))
(error "Problem loading theme %s" theme)))

(defun circadian--encode-time (hour min)
"Encode HOUR hours and MIN minutes into a valid format for `run-at-time'."
(let ((now (decode-time)))
(let ((day (nth 3 now))
(month (nth 4 now))
(year (nth 5 now))
(zone (current-time-zone)))
(encode-time 0 min hour day month year zone))))

(defun circadian-mapc (entry)
"Map over `circadian-themes' to run a timer for each ENTRY."
(let ((time (circadian-match-sun (cl-first entry)))
(24-hours 86400))
(let ((theme (cdr entry))
(repeat-after 24-hours)
(at-hour (number-to-string (cl-first time)))
(at-seconds (number-to-string (cl-second time))))
(run-at-time (concat at-hour ":" at-seconds)
(run-at (circadian--encode-time (cl-first time)
(cl-second time))))
(run-at-time run-at
repeat-after
'circadian-enable-theme
theme))))
Expand All @@ -103,7 +112,7 @@
theme-list))

(defun circadian-activate-latest-theme ()
"Check which themes are overdue to be activated and load the last.
"Check which themes are overdue to be activated and load the last.)
`circadian-themes' is expected to be sorted by time for now."
(let ((past-themes (circadian-filter-inactivate-themes
circadian-themes
Expand Down Expand Up @@ -143,7 +152,8 @@
;;;###autoload
(defun circadian-setup ()
"Setup circadian based on `circadian-themes'."
(mapc 'circadian-mapc circadian-themes))
(mapc 'circadian-mapc circadian-themes)
(circadian-activate-latest-theme))

(provide 'circadian)
;;; circadian.el ends here

0 comments on commit 9894361

Please sign in to comment.