Comment detail

n日後を返す関数を返す関数 (Nested Flatten)
日付型というのは見つからなかったので、構造体の定義からやりました。
(setq now (datetime-now))
(print now)
 => #S(DATETIME :YEAR 2007 :MONTH 7 :DATE 22 :HOUR 15 :MINUTE 35 :SECOND 50)
(print (funcall (n-days-after 10) now))
 => #S(DATETIME :YEAR 2007 :MONTH 8 :DATE 1 :HOUR 15 :MINUTE 35 :SECOND 50)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(defstruct datetime year month date hour minute second)

(defun datetime-now ()
  (multiple-value-bind
    (second minute hour date month year)
    (get-decoded-time)
    (make-datetime :year year :month month
                   :date date :hour hour
                   :minute minute :second second)))

(defun n-days-after (n)
  #'(lambda (date) 
      (multiple-value-bind
        (second minute hour date month year)
        (decode-universal-time 
          (+ (encode-universal-time 
               (datetime-second date) (datetime-minute date)
               (datetime-hour date) (datetime-date date)
               (datetime-month date) (datetime-year date))
             (* n 60 60 24)))
        (make-datetime :year year :month month
                       :date date :hour hour
                       :minute minute :second second))))
日付はuniversal-timeで持っておいて、日付用のformat関数を用意して、表示する時に変換する方が、らしい方法かもしれないと思いました。

(setq now (get-universal-time))
(date-format t now)
 => 2007/7/22 16:1:53
(date-format t (funcall (n-days-after 10) now))
 => 2007/8/1 16:1:53
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
(defun date-format (destination arg-date)
  (multiple-value-bind
    (second minute hour date month year)
    (decode-universal-time arg-date)
    (format destination "~d/~d/~d ~d:~d:~d"
            year month date hour minute second)))

(defun n-days-after (n)
  #'(lambda (arg-date) 
        (+ arg-date (* n 60 60 24))))

Index

Feed

Other

Link

Pathtraq

loading...