3
A
回答
2
答案要求用戶設置一個預定義假期的日曆,就像這個例子。我已經包含了5月9日的測試假期 - 如果用戶希望在除5月9日以外的任何一天測試此功能,用戶可能希望將任意測試假期更改爲測試執行的任何一天 - 在功能測試完成後,測試條目可以被刪除。
有關如何格式化假期的示例,請參閱庫holidays.el
中變量calendar-holidays
的文檔字符串 - 例如holiday-fixed
; holiday-float
; holiday-sexp
; (lunar-phases)
; (solar-equinoxes-solstices)
; holiday-hebrew
; holiday-islamic
; holiday-bahai
; holiday-julian
; holiday-chinese
;等等
你怎麼可以試用這個例子?:將代碼塊/複製/粘貼到您的*scratch*
緩衝區;並輸入M-x eval-buffer RET
;然後鍵入M-x is-holiday RET
。這是一個功能齊全的工作草案。如果您在嘗試之後決定不喜歡它,只需重新啓動Emacs,在嘗試之前您會回到您的位置。
已執行的測試是在Emacs的最新公開版本中完成的:2014-10-20在構建器10上的GNU Emacs 24.4.1(x86_64-apple-darwin10.8.0,NSapple-appkit-1038.36) -6.porkrind.org。
(require 'holidays)
(defcustom my-custom-holiday-list (mapcar 'purecopy '(
(holiday-fixed 1 1 "New Year's Day")
(holiday-float 1 1 3 "Martin Luther King Day")
(holiday-float 2 1 3 "President's 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's 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."))))
相關問題
- 1. Elisp中的過濾函數
- 2. Mutator elisp函數
- 3. 評估Emacs中的隨機elisp函數
- 4. elisp中的lambda函數範圍
- 5. 如何在elisp中定義以「塊」作爲參數的函數?
- 6. 確定真/假
- 7. Elisp函數返回標記而不是正確的值
- 8. Elisp函數返回值
- 9. 函數的一次性假定
- 10. 假期日期約定C#
- 11. 手動假定日期 - 更新日期與自己的假設
- 12. 如何將列表作爲elisp中的函數的參數?
- 13. 確定日期和日期的最近日期的日期函數
- 14. elisp新手問題:在org.el中找不到'filename'函數定義?
- 15. 窗口函數假定null排序低 - 預期行爲?
- 16. 從Oracle函數中確定日期的工資
- 17. 用Excel函數確定一個月中的上個星期五
- 18. 確定生成日期是否屬於假期(PHP)?
- 19. 如何確定日期是否爲假期
- 20. 如何動態確定某個國家的假期?
- 21. 將函數傳遞給elisp中的參數
- 22. 星期數的確定
- 23. 是否有列出給定緩衝區中的標記的Elisp函數?
- 24. 假期或假期日曆
- 25. 如何在假期或假期中使用「mime」秒數
- 26. Oracle中的Dertermine假期
- 27. Matlab中的德國假期
- 28. 哈希函數的確定
- 29. 確定函數的極值
- 30. 指定elisp的命令