diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-05 21:34:52 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-05 21:34:56 +0200 |
commit | 228d485e10f44b402843badabba4f09599f3c2a3 (patch) | |
tree | 2b00de0ea6a1b7a9c4cceff31f7ec009941731f7 /module | |
parent | Add profile! macro. (diff) | |
download | calp-228d485e10f44b402843badabba4f09599f3c2a3.tar.gz calp-228d485e10f44b402843badabba4f09599f3c2a3.tar.xz |
Change to only call get-datetime in parse.
Diffstat (limited to '')
-rw-r--r-- | module/datetime.scm | 56 | ||||
-rw-r--r-- | module/datetime/util.scm | 5 | ||||
-rw-r--r-- | module/output/html.scm | 4 | ||||
-rw-r--r-- | module/vcomponent/datetime.scm | 8 | ||||
-rw-r--r-- | module/vcomponent/parse.scm | 12 |
5 files changed, 41 insertions, 44 deletions
diff --git a/module/datetime.scm b/module/datetime.scm index 0cca216b..b2a3d38e 100644 --- a/module/datetime.scm +++ b/module/datetime.scm @@ -188,7 +188,7 @@ [else (error "Object not a date, time, or datetime object ~a" date/-time)])) (define-public (as-time date/-time) - (cond [(datetime? date/-time) (get-time% (get-datetime date/-time))] + (cond [(datetime? date/-time) (get-time% date/-time)] [(date? date/-time) (time)] [(time? date/-time) date/-time] [else (error "Object not a date, time, or datetime object ~a" date/-time)])) @@ -219,10 +219,8 @@ (= (second a) (second b)))) (define-public (datetime= a b) - (let ((a (get-datetime a)) - (b (get-datetime b))) - (and (date= (get-date a) (get-date b)) - (time= (get-time% a) (get-time% b))))) + (and (date= (get-date a) (get-date b)) + (time= (get-time% a) (get-time% b)))) (define-many define-public (date=?) date= @@ -276,18 +274,14 @@ (time< a b))) (define-public (datetime< a b) - (let ((a (get-datetime a)) - (b (get-datetime b))) - (if (date= (get-date a) (get-date b)) - (time< (get-time% a) (get-time% b)) - (date< (get-date a) (get-date b))))) + (if (date= (get-date a) (get-date b)) + (time< (get-time% a) (get-time% b)) + (date< (get-date a) (get-date b)))) (define-public (datetime<= a b) - (let ((a (get-datetime a)) - (b (get-datetime b))) - (if (date= (get-date a) (get-date b)) - (time<= (get-time% a) (get-time% b)) - (date<= (get-date a) (get-date b))))) + (if (date= (get-date a) (get-date b)) + (time<= (get-time% a) (get-time% b)) + (date<= (get-date a) (get-date b)))) (define-public (date/-time< a b) (datetime< (as-datetime a) (as-datetime b))) @@ -560,15 +554,13 @@ ;; NOTE that base is re-normalized, but change isn't. This is due to base ;; hopefully being a real date, but change just being a difference. (define-public (datetime+ base change) - (let (; (base (get-datetime base)) - ) - (let* ((time overflow (time+ (get-time% base) (get-time% change)))) - (datetime date: (date+ (get-date base) - (get-date change) - (date day: overflow)) - time: time - tz: (get-timezone base) - )))) + (let* ((time overflow (time+ (get-time% base) (get-time% change)))) + (datetime date: (date+ (get-date base) + (get-date change) + (date day: overflow)) + time: time + tz: (get-timezone base) + ))) ;; (define (datetime->srfi-19-date date) ;; ((@ (srfi srfi-19) make-date) @@ -658,16 +650,14 @@ (day = (- 1))))) -(define-public (datetime-difference end* start*) +(define-public (datetime-difference end start) ;; NOTE Makes both start and end datetimes in the current local time. - (let ((end (get-datetime end*)) - (start (get-datetime start*))) - (let* ((fixed-time overflow (time- (get-time% end) - (get-time% start)))) - (datetime date: (date-difference (date- (get-date end) - (date day: overflow)) - (get-date start)) - time: fixed-time)))) + (let* ((fixed-time overflow (time- (get-time% end) + (get-time% start)))) + (datetime date: (date-difference (date- (get-date end) + (date day: overflow)) + (get-date start)) + time: fixed-time))) diff --git a/module/datetime/util.scm b/module/datetime/util.scm index 910c42d3..d310992c 100644 --- a/module/datetime/util.scm +++ b/module/datetime/util.scm @@ -157,9 +157,8 @@ str))) (define*-public (datetime->string datetime optional: (fmt "~Y-~m-~dT~H:~M:~S") key: allow-unknown?) - (define dt (get-datetime datetime)) - (define date (get-date dt)) - (define time ((@ (datetime) get-time%) dt)) + (define date (get-date datetime)) + (define time ((@ (datetime) get-time%) datetime)) (with-output-to-string (lambda () (fold (lambda (token state) diff --git a/module/output/html.scm b/module/output/html.scm index 3b17d81b..6dc9591b 100644 --- a/module/output/html.scm +++ b/module/output/html.scm @@ -234,12 +234,12 @@ (make-block ev `((class - ,(when (date<? (as-date (get-datetime (attr ev 'DTSTART))) date) + ,(when (date<? (as-date (attr ev 'DTSTART)) date) " continued") ;; TODO all day events usually have the day after as DTEND. ;; So a whole day event the 6 june would have a DTEND of the ;; 7 june. - ,(when (date<? date (as-date (get-datetime (attr ev 'DTEND)))) + ,(when (date<? date (as-date (attr ev 'DTEND))) " continuing")) (style ,style)))) diff --git a/module/vcomponent/datetime.scm b/module/vcomponent/datetime.scm index 44776516..68909809 100644 --- a/module/vcomponent/datetime.scm +++ b/module/vcomponent/datetime.scm @@ -66,9 +66,9 @@ Event must have the DTSTART and DTEND attribute set." (date-max start-date (attr e 'DTSTART))) (datetime-difference (datetime-min (datetime date: (date+ end-date (date day: 1))) - (get-datetime (attr e 'DTEND))) + (attr e 'DTEND)) (datetime-max (datetime date: start-date) - (get-datetime (attr e 'DTSTART)))))) + (attr e 'DTSTART))))) ;; Returns the length of the part of @var{e} which is within the day ;; starting at the time @var{start-of-day}. @@ -76,8 +76,8 @@ Event must have the DTSTART and DTEND attribute set." ;; to a datetime to allow for more explicit TZ handling? (define-public (event-length/day date e) ;; TODO date= > 2 elements - (let ((start (get-datetime (attr e 'DTSTART))) - (end (get-datetime (attr e 'DTEND)))) + (let ((start (attr e 'DTSTART)) + (end (attr e 'DTEND))) (cond [(and (date= (as-date start) (as-date end)) (date= (as-date start) diff --git a/module/vcomponent/parse.scm b/module/vcomponent/parse.scm index b5bb17e9..a21d6ca1 100644 --- a/module/vcomponent/parse.scm +++ b/module/vcomponent/parse.scm @@ -118,10 +118,18 @@ (let ((type (and=> (prop vline 'VALUE) car))) (if (or (and=> type (cut string=? <> "DATE-TIME")) (string-contains (value vline) "T")) - (set! (value vline) (parse-ics-datetime (value vline) tz) + ;; TODO TODO TODO + ;; we move all parsed datetimes to local time here. This + ;; gives a MASSIVE performance boost over calling get-datetime + ;; in all procedures which want to guarantee local time for proper calculations. + ;; 20s vs 70s runtime on my laptop. + ;; We sohuld however save the original datetime in a file like X-HNH-DTSTART, + ;; since we don't want to lose that information. + (set! (value vline) (get-datetime (parse-ics-datetime (value vline) tz)) (prop vline 'VALUE) 'DATE-TIME) (set! (value vline) (parse-ics-date (value vline)) - (prop vline 'VALUE) 'DATE))))])) + (prop vline 'VALUE) 'DATE))) + )])) ;; Reads a vcomponent from the given port. (define-public (parse-calendar port) |