2010-11-17 14 views
1

我正在編輯orgmode,這是emacs的時間管理模式。我添加了一些新的時間函數。 在我的另外,我需要確定給定日期的一週中的某一天。我使用下面的代碼:Lisp:decode-universal-time is void

(defun org-day-of-week (day month year) 
(nth-value 6 (decode-universal-time (encode-universal-time 0 0 0 day month year 0) 0))) 

執行這段代碼給我的錯誤:

第n-值:符號的功能定義是無效:解碼萬能時間

我是新來口齒不清,並且找不到與此錯誤相關的任何信息。我想有些圖書館沒有加載或可用。 任何人都可以請說明這一點?

的問候, 歐文Vrolijk Snow.nl

回答

3

本質decode-universal-time是Common Lisp的功能。這些不一定在emacs-lisp中可用。在本地emacs中快速檢查表明這是事實。

一些接近你原來的實現將是:

(defun org-day-of-week (year month day) 
    (nth 6 
     (decode-time 
      (date-to-time 
      (format "%d-%02d-%02dT00:00:00" year month day))))) 

你應該能夠(也許與date-to-time一起選擇)使用decode-time代替:

decode-time is a built-in function in `C source code'. (decode-time &optional specified-time) Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE). The optional specified-time should be a list of (HIGH LOW . IGNORED), as from `current-time' and `file-attributes', or nil to use the current time. The obsolete form (HIGH . LOW) is also still accepted. The list has the following nine members: SEC is an integer between 0 and 60; SEC is 60 for a leap second, which only some operating systems support. MINUTE is an integer between 0 and 59. HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31. MONTH is an integer between 1 and 12. YEAR is an integer indicating the four-digit year. DOW is the day of week, an integer between 0 and 6, where 0 is Sunday. DST is t if daylight saving time is in effect, otherwise nil. ZONE is an integer indicating the number of seconds east of Greenwich. (Note that Common Lisp has different meanings for DOW and ZONE.)
0

我還沒有發現這個問題的根源,卻發現一個解決辦法:

(defun day-of-week (day month year) 
    "Returns the day of the week as an integer. 
Sunday is 0. Works for years after 1752." 
    (let ((offset '(0 3 2 5 0 3 5 1 4 6 2 4))) 
    (when (< month 3) 
     (decf year 1)) 
    (mod 
    (truncate (+ year 
        (/ year 4) 
        (/ (- year) 
        100) 
        (/ year 400) 
        (nth (1- month) offset) 
        day 
        -1)) 
    7))) 
2

Vatine的answer的清潔器版本:

(defun day-of-week (year month day) 
    "Return the day of the week given a YEAR MONTH DAY" 
    (nth 6 (decode-time (encode-time 0 0 0 day month year)))) 

decode-timeencode-timedocumented here

相關問題