Skip to content

Commit

Permalink
TP->T64 COMPATIBILITY SHIM: gnucash/libgnucash/app-utils/options.scm
Browse files Browse the repository at this point in the history
This commit adds a compatibiliy shim. Although the rest of gnucash
can be converted to time64, this shim allows a Gnucash session to
load reports saved with timepairs.
  • Loading branch information
christopherlam committed Jan 8, 2018
1 parent 7550ccf commit d41ad85
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions libgnucash/app-utils/options.scm
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,24 @@
subtype
relative-date-list)
(define (date-legal date)
(and (pair? date)
(or
(and (pair? date)
(or
(and (eq? 'relative (car date)) (symbol? (cdr date)))
(and (eq? 'absolute (car date))
(pair? (cdr date))
(exact? (cadr date))
(exact? (cddr date))))))
(and (eq? 'absolute (car date))
(or (and (pair? (cdr date)) ; we can still accept
(exact? (cadr date)) ; old-style timepairs
(exact? (cddr date)))
(and (number? (cdr date))
(exact? (cdr date))))))))
(define (maybe-convert-to-time64 date)
;; compatibility shim. this is triggered only when date is type
;; (cons 'absolute (cons sec nsec)) - we'll convert to
;; (cons 'absolute sec). this shim must always be kept for gnucash
;; to reload saved reports, or reload reports launched at startup,
;; which had been saved as timepairs.
(if (pair? (cdr date))
(cons (car date) (cadr date))
date))
(define (list-lookup list item)
(cond
((null? list) #f)
Expand All @@ -582,7 +593,7 @@
(lambda () value)
(lambda (date)
(if (date-legal date)
(set! value date)
(set! value (maybe-convert-to-time64 date))
(gnc:error "Illegal date value set:" date)))
default-getter
(gnc:restore-form-generator value->string)
Expand Down

0 comments on commit d41ad85

Please sign in to comment.