Replace sprintf with Guile's built-in format.

This commit is contained in:
John Ralls
2018-02-17 14:58:18 -08:00
parent e3cd9f88c9
commit 48bdab38d4
51 changed files with 151 additions and 1416 deletions

View File

@@ -22,7 +22,6 @@
(use-modules (gnucash core-utils)
(gnucash printf)
(gnucash gettext))
(define gnc:reldate-list '())
@@ -72,7 +71,7 @@
(gnc-locale-to-utf8 (strftime "%Y" datevec)))
(define (gnc:date-get-quarter-string datevec)
(sprintf #f "Q%d" (gnc:date-get-quarter datevec)))
(format #f "Q~d" (gnc:date-get-quarter datevec)))
(define (gnc:date-get-quarter-year-string datevec)
(string-append
@@ -92,7 +91,7 @@
604800))
(begin-string (qof-print-date (+ beginweekt64 345600)))
(end-string (qof-print-date (+ beginweekt64 864000))))
(sprintf #f (_ "%s to %s") begin-string end-string)))
(format #f (_ "~s to ~s") begin-string end-string)))
; (let ((begin-string (qof-print-date
; (+ (* (gnc:date-get-week
@@ -104,7 +103,7 @@
; (gnc:time64-start-day-time
; (gnc-mktime datevec)))
; 604800) 864000))))
; (sprintf #f (_ "%s to %s") begin-string end-string)))
; (format #f (_ "~s to ~s") begin-string end-string)))
;; is leap year?
(define (gnc:leap-year? year)

View File

@@ -58,7 +58,7 @@ GNC_ADD_SCHEME_TARGETS(scm-test-c-interface
FALSE
)
GNC_ADD_SCHEME_TESTS(${test_app_utils_scheme_SOURCES})
GNC_ADD_SCHEME_TESTS("${test_app_utils_scheme_SOURCES}")
# Doesn't work yet:
GNC_ADD_TEST_WITH_GUILE(test-app-utils "${test_app_utils_SOURCES}" APP_UTILS_TEST_INCLUDE_DIRS APP_UTILS_TEST_LIBS)

View File

@@ -3,9 +3,10 @@
(use-modules (gnucash engine test test-extras))
(define (run-test)
(and (test test-weeknum-calculator)))
(and (test test-weeknum-calculator)
(test test-date-get-quarter-string)))
(define (create-time64 l)
(define (create-datevec l)
(let ((now (gnc-localtime (current-time))))
(set-tm:sec now (list-ref l 5))
(set-tm:min now (list-ref l 4))
@@ -14,6 +15,10 @@
(set-tm:mon now (list-ref l 1))
(set-tm:year now (list-ref l 0))
(set-tm:isdst now -1)
now))
(define (create-time64 l)
(let ((now (create-datevec l)))
(gnc-mktime now)))
(define (weeknums-equal? pair-of-dates)
@@ -36,3 +41,15 @@
(not (weeknums-equal? (cons '(1969 12 28 0 0 1)
'(1970 1 5 0 0 1))))
))
(define (test-date-get-quarter-string)
(and (or (string=? "Q1" (gnc:date-get-quarter-string (create-datevec '(2001 2 14 11 42 23))))
(begin (format #t "Expected Q1, got ~a~%" (gnc:date-get-quarter-string (creaete-datevec '(2001 2 14 11 42 23))))
#f))
(or (string=? "Q2" (gnc:date-get-quarter-string (create-datevec '(2013 4 23 18 11 49))))
(begin (format #t "Expected Q1, got ~a~%" (gnc:date-get-quarter-string (create-datevec '(2001 2 14 11 42 23))))
#f))
(or (string=? "Q3" (gnc:date-get-quarter-string (create-datevec '(1997 9 11 08 14 21))))
(begin (format #t "Expected Q1, got ~a~%" (gnc:date-get-quarter-string (create-datevec '(2001 2 14 11 42 23)))))
#f)))