Comment detail

指定された日の存在する週 (Nested Flatten)
Scheme(Gauche)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(use srfi-1)
(use srfi-19)
(define (week-days year month day)
  (let* ((now (make-date 0 0 0 0 day month year
                         (date-zone-offset (current-date))))
         (start (- (date->modified-julian-day now) (date-week-day now) -1)))
    (map (lambda (x)
           (let* ((date (modified-julian-day->date (+ start x)))
                  (dow (list-ref '("日""月""火""水""木""金""土")
                                 (date-week-day date)))
                  (fmt (date->string (modified-julian-day->date (+ start x))
                                     #`"~1(,dow)")))
             fmt))
         (iota 5))))


;; 出力例
gosh> (for-each print (week-days 2007 7 6))
2007-07-02()
2007-07-03()
2007-07-04()
2007-07-05()
2007-07-06()

gosh> (for-each print (week-days 2007 7 31))
2007-07-30()
2007-07-31()
2007-08-01()
2007-08-02()
2007-08-03()

gosh> (for-each print (week-days 2007 12 31))
2007-12-31()
2008-01-01()
2008-01-02()
2008-01-03()
2008-01-04()

Index

Feed

Other

Link

Pathtraq

loading...