Add some resistance for timesheet file syntax error
This commit is contained in:
parent
57d05af68f
commit
d086efdafe
@ -89,12 +89,17 @@
|
|||||||
;;; Parse task string and return list:
|
;;; Parse task string and return list:
|
||||||
;;; '((list of path elements) start-date stop-date duration)
|
;;; '((list of path elements) start-date stop-date duration)
|
||||||
(define (parse-task-string str)
|
(define (parse-task-string str)
|
||||||
|
(let ((str (string-trim-both str)))
|
||||||
|
(if (or (zero? (string-length str))
|
||||||
|
(equal? (string-ref str 0) #\#))
|
||||||
|
#f
|
||||||
(let ((path
|
(let ((path
|
||||||
(let ((path-end (string-index str #\:)))
|
(let ((path-end (string-index str #\:)))
|
||||||
(if (not path-end) '()
|
(if (not path-end) #f
|
||||||
(path-split str 0 path-end))))
|
(path-split str 0 path-end))))
|
||||||
(dates (substring/find str #\[ #\])))
|
(dates (substring/find str #\[ #\])))
|
||||||
(if (null? dates) '()
|
(if (or (not path) (not dates))
|
||||||
|
#f
|
||||||
(let ((date-start (string->date (car dates) date-format)))
|
(let ((date-start (string->date (car dates) date-format)))
|
||||||
(let-values (((date-end duration)
|
(let-values (((date-end duration)
|
||||||
(if (null? (cdr dates))
|
(if (null? (cdr dates))
|
||||||
@ -104,7 +109,7 @@
|
|||||||
(date->time-utc date-end)
|
(date->time-utc date-end)
|
||||||
(date->time-utc date-start))))
|
(date->time-utc date-start))))
|
||||||
(values date-end duration)))))
|
(values date-end duration)))))
|
||||||
(list path date-start date-end duration))))))
|
(list path date-start date-end duration))))))))
|
||||||
|
|
||||||
;;; Parse timesheet file and return list of tasks
|
;;; Parse timesheet file and return list of tasks
|
||||||
(define (read-timesheet filename)
|
(define (read-timesheet filename)
|
||||||
@ -114,7 +119,8 @@
|
|||||||
(let ((line (get-line port)))
|
(let ((line (get-line port)))
|
||||||
(if (eof-object? line)
|
(if (eof-object? line)
|
||||||
(reverse recs)
|
(reverse recs)
|
||||||
(loop (cons (parse-task-string line) recs))))))))
|
(loop (let ((item (parse-task-string line)))
|
||||||
|
(if item (cons item recs) recs)))))))))
|
||||||
|
|
||||||
;;; Return difference of two dates
|
;;; Return difference of two dates
|
||||||
(define (date-difference d1 d2)
|
(define (date-difference d1 d2)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user