Skip to content

Commit

Permalink
Fix issue #63 (take 2)
Browse files Browse the repository at this point in the history
Handle different values of `calendar-date-style` in calfw-cal.el and not
in calfw.el.

The previous attempt to fix this issue caused new problems with org-mode
date ranges.
  • Loading branch information
Jehops committed May 28, 2016
1 parent 973ffa3 commit 8de82be
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
35 changes: 28 additions & 7 deletions calfw-cal.el
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,34 @@ from the diary schedule data."
(list (cons 'periods
(map 'list (function (lambda (period)
(let ((spec (read (substring (car period) 2))))
(list (list (nth 1 spec)
(nth 2 spec)
(nth 3 spec))
(list (nth 4 spec)
(nth 5 spec)
(nth 6 spec))
(cdr period)))))
(cond
((eq calendar-date-style 'american)
(list
(list (nth 1 spec)
(nth 2 spec)
(nth 3 spec))
(list (nth 4 spec)
(nth 5 spec)
(nth 6 spec))
(cdr period)))
((eq calendar-date-style 'european)
(list
(list (nth 2 spec)
(nth 1 spec)
(nth 3 spec))
(list (nth 5 spec)
(nth 4 spec)
(nth 6 spec))
(cdr period)))
((eq calendar-date-style 'iso)
(list
(list (nth 2 spec)
(nth 3 spec)
(nth 1 spec))
(list (nth 5 spec)
(nth 6 spec)
(nth 4 spec))
(cdr period)))))))
periods))))))

(defvar cfw:cal-schedule-map
Expand Down
28 changes: 8 additions & 20 deletions calfw.el
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,6 @@ ones of DATE2. Otherwise is `nil'."
((<= cfw:week-days num) (- num cfw:week-days))
(t num)))))

(defun cfw:month-day-year (date)
"Transform a diary DATE list to a month day year list."
(cond
((eq calendar-date-style 'american) date)
((eq calendar-date-style 'european)
(list (nth 1 date) (nth 0 date) (nth 2 date)))
((eq calendar-date-style 'iso)
(list (nth 1 date) (nth 2 date) (nth 0 date)))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -1557,8 +1548,7 @@ PREV-CMD and NEXT-CMD are the moving view command, such as `cfw:navi-previous(ne
BEGIN and END from the PERIODS-EACH-DAYS."
(loop for row-num from 0 below 30 ; assuming the number of stacked periods is less than 30
unless
(loop for d in (cfw:enumerate-days
(cfw:month-day-year begin) (cfw:month-day-year end))
(loop for d in (cfw:enumerate-days begin end)
for periods-stack = (cfw:contents-get d periods-each-days)
if (and periods-stack (assq row-num periods-stack))
return t)
Expand All @@ -1567,15 +1557,13 @@ BEGIN and END from the PERIODS-EACH-DAYS."
(defun cfw:render-periods-place (periods-each-days row period)
"[internal] Assign PERIOD content to the ROW-th row on the days of the period,
and append the result to periods-each-days."
(let ((begin (cfw:month-day-year (car period)))
(end (cfw:month-day-year (cadr period))))
(loop for d in (cfw:enumerate-days begin end)
for periods-stack = (cfw:contents-get-internal d periods-each-days)
if periods-stack
do (setcdr periods-stack (append (cdr periods-stack)
(list (list row period))))
else
do (push (cons d (list (list row period))) periods-each-days)))
(loop for d in (cfw:enumerate-days (car period) (cadr period))
for periods-stack = (cfw:contents-get-internal d periods-each-days)
if periods-stack
do (setcdr periods-stack (append (cdr periods-stack)
(list (list row period))))
else
do (push (cons d (list (list row period))) periods-each-days))
periods-each-days)

(defun cfw:render-periods-stacks (model)
Expand Down

0 comments on commit 8de82be

Please sign in to comment.