aboutsummaryrefslogtreecommitdiff
path: root/module/vcomponent/datetime/output.scm
blob: 2b528423c90b68567d463b8e5711cb2353f0265d (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(define-module (vcomponent datetime output)
  :use-module (hnh util)
  :use-module (datetime)
  :use-module (vcomponent base)
  :use-module (text util)
  )

;; ev → sxml
(define-public (format-recurrence-rule ev)
  `("Upprepas "
    ,((@ (vcomponent recurrence display) format-recurrence-rule)
      (prop ev 'RRULE))
    ,@(awhen (prop* ev 'EXDATE)
             (list
              ", undantaget "
              (add-enumeration-punctuation
               (map (lambda (d)
                      (if (date? d)
                          ;; NOTE possibly show year?
                          (date->string d "~e ~b")
                          ;; NOTE only show time when it's different than the start time?
                          ;; or possibly only when FREQ is hourly or lower.
                          (if (memv ((@ (vcomponent recurrence internal) freq)
                                     (prop ev 'RRULE))
                                    '(HOURLY MINUTELY SECONDLY))
                              (datetime->string d "~e ~b ~k:~M")
                              (datetime->string d "~e ~b"))))
                    (map value it)))))
    "."))


;; Takes an event, and returns a pretty string for the time interval
;; the event occupies.
(define-public (fmt-time-span ev)
  (cond [(prop ev 'DTSTART) date?
         => (lambda (s)
              (cond [(prop ev 'DTEND)
                     => (lambda (e)
                          (if (date= e (date+ s (date day: 1)))
                              "~Y-~m-~d"  ; start = end, only return one value
                              (values "~Y-~m-~d"
                                      "~Y-~m-~d")))]
                    ;; no end value, just return start
                    [else (date->string s)]))]
        [else ; guaranteed datetime
         (let ((s (prop ev 'DTSTART))
               (e (prop ev 'DTEND)))
           (if e
               (let ((fmt-str (if (date= (get-date s) (get-date e))
                                  "~H:~M" "~Y-~m-~d ~H:~M")))
                 (values fmt-str fmt-str))
               "~Y-~m-~d ~H:~M"))]))