aboutsummaryrefslogtreecommitdiff
path: root/module/calp/entry-points/ical.scm
blob: e164c340e1c4836f902f11a515a2aecb90bc2369 (plain)
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
(define-module (calp entry-points ical)
  :export (main)
  :use-module (hnh util)
  :use-module (hnh util options)
  :use-module (vcomponent formats ical output)
  :use-module (ice-9 getopt-long)
  :use-module (datetime)
  :use-module (calp translation)
  :use-module (calp translation)
  )

(define opt-spec
  `((from (value #t) (single-char #\F))
    (to (value #t) (single-char #\T)
        (description ,(_ "Returns all elements between these two dates.")))
    (help (single-char #\h)
          (description ,(_ "Print this help.")))))

(define (main args)
  (define opts (getopt-long args (getopt-opt opt-spec)))

  (define start (cond [(option-ref opts 'from #f) => parse-freeform-date]
                      [else (start-of-month (current-date))]))
  (define end   (cond [(option-ref opts 'to  #f) => parse-freeform-date]
                      ;; [else (normalize-date* (set (month start) = (+ 1)))]
                      [(date+ start (date month: 1))]
                      ))

  (when (option-ref opts 'help #f)
    (print-arg-help opt-spec)
    (throw 'return))

  (print-events-in-interval start end))