Holiday function in elisp

Any function here to determine the current system date - holiday or not in elisp.

acts as follows.

(is-holiday (current-time))

      

+3


source to share


1 answer


The response requires the user to set up a calendar of predefined holidays, such as this example. I have included a test vacation on May 9th - if the user wants to test this feature on any day other than May 9th, the user may wish to change the arbitrary test vacation on any day the test is in progress - after testing the feature, the test record can be deleted.

For examples of how to format holidays, see the doc line for the variable calendar-holidays

in the library holidays.el

- for example holiday-fixed

; holiday-float

; holiday-sexp

; (lunar-phases)

; (solar-equinoxes-solstices)

; holiday-hebrew

; holiday-islamic

; holiday-bahai

; holiday-julian

; holiday-chinese

; and etc.

How can you try this example? : lock / copy / paste the code into the clipboard *scratch*

; and enter M-x eval-buffer RET

; and then enter M-x is-holiday RET

. This is a fully functional working project. If you decide you donโ€™t like it when you try it, just restart Emacs and you will be back to where you were before you tried it.



The testing that was done was done using the latest Emacs publication: GNU Emacs 24.4.1 (x86_64-apple-darwin10.8.0, NS apple-appkit-1038.36) 2014-10-20 at builder10-6.porkrind.org.

(require 'holidays)

(defcustom my-custom-holiday-list (mapcar 'purecopy '(
  (holiday-fixed 1 1 "New Year Day")
  (holiday-float 1 1 3 "Martin Luther King Day")
  (holiday-float 2 1 3 "President Day")
  (holiday-float 5 1 -1 "Memorial Day")
  ;; ARBITRARY TEST HOLIDAY -- MAY 9
  (holiday-fixed 5 9 "Arbitrary Test Holiday -- May 9")
  (holiday-fixed 7 4 "Independence Day")
  (holiday-float 9 1 1 "Labor Day")
  (holiday-float 10 1 2 "Columbus Day")
  (holiday-fixed 11 11 "Veteran Day")
  (holiday-float 11 4 4 "Thanksgiving")
  (holiday-fixed 12 25 "Christmas")
  (solar-equinoxes-solstices)
  (holiday-sexp calendar-daylight-savings-starts
    (format "Daylight Saving Time Begins %s"
      (solar-time-string
        (/ calendar-daylight-savings-starts-time (float 60))
        calendar-standard-time-zone-name)))
  (holiday-sexp calendar-daylight-savings-ends
      (format "Daylight Saving Time Ends %s"
       (solar-time-string
         (/ calendar-daylight-savings-ends-time (float 60))
         calendar-daylight-time-zone-name))) ))
  "Custom holidays defined by the user."
  :type 'sexp
  :group 'holidays)

(defun is-holiday ()
  "Is today a holiday?"
(interactive)
  (let* (
      (d1 (time-to-days (current-time)))
      (date (calendar-gregorian-from-absolute d1))
      ee
      res-holidays
      (displayed-month (nth 0 date))
      (displayed-year (nth 2 date))
      (holiday-list
        (dolist (p my-custom-holiday-list res-holidays)
          (let* (h)
           (when (setq h (eval p))
             (setq res-holidays (append h res-holidays)))))) )
    (mapcar
      (lambda (x)
        (let ((txt (format "%s -- %s" (car x) (car (cdr x)))))
          (when (eq d1 (calendar-absolute-from-gregorian (car x)))
            (push txt ee))))
      holiday-list)
    (if ee
      (message "The following holiday(s) is/are today:  %s" (nreverse ee))
      (message "Today is not a holiday."))))

      

+2


source







All Articles