From 4196e95118152bd30ccfcf4aedc665a3543ede47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Wed, 22 Mar 2023 22:58:02 +0100 Subject: [PATCH] Finish period documentation, cleanup period usage. --- README.md | 43 +++++++++++++++++++++++++++++++++++++------ member-file.scm | 3 +-- period.scm | 9 +++------ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index de7863d..7fb7e19 100644 --- a/README.md +++ b/README.md @@ -194,17 +194,48 @@ Returns a new valid month that comes ```n``` months after ```m```. If This module implements simple calendar period handling with month granularity. -sort-period-markers + (period-markers->periods l) -period-markers->periods +* ```l``` - list of sorted (list tag month) -periods-duration +Converts a list of period markers ```l``` into actual periods where +each period is represented by ```(list start-month end-month)```. -month-in-periods? +The ```end-month``` may be ```#f``` in which case it is an open-ended +period which has not ended yet. -periods->string + (periods-duration l) -periods-match +* ```l``` - list of periods + +Returns the total duration in months of the periods given in the list +```l```. Each period is represented as ```(list start-month +end-month)```. + + (month-in-periods? ps [m (*current-month*)]) + +* ```ps``` - a list of periods +* ```m``` - a valid month - defaults to ```(*current-month*)``` + +Returns ```#t``` if given month ```m``` lies within any of the periods +given in the list of periods ```ps```. + + (periods->string ps) + +* ```ps``` - a list of periods + +Returns a string representing all the periods given in the list of +periods ```ps```. The periods are represented as +````"YYYY-MM..YYYY-MM"``` and an open end is substituded with +```"____-__"```. + + + (periods-match ps [m (*current-month*)]) + +* ```ps``` - a list of periods + +Returns the period from the list of periods ```ps``` the given month +```m``` falls into. If no period matches, returns ```#f```. ### Primes diff --git a/member-file.scm b/member-file.scm index f6d07e5..76244d6 100644 --- a/member-file.scm +++ b/member-file.scm @@ -185,8 +185,7 @@ (define (convert-member-key:markers->periods m k) (if (dict-has-key? m k) (let* ((res (period-markers->periods - (sort-period-markers - (dict-ref m k '())))) + (dict-ref m k '()))) (ok? (car res)) (periods (cadr res)) (msg (caddr res)) diff --git a/period.scm b/period.scm index 69ed9d2..d51b943 100644 --- a/period.scm +++ b/period.scm @@ -28,7 +28,6 @@ (module period ( - sort-period-markers period-markers->periods periods-duration month-in-periods? @@ -58,7 +57,7 @@ ;; Converts list of start/stop markers to list of pairs of months - ;; periods. (define (period-markers->periods l) - (let loop ((l l) + (let loop ((l (sort-period-markers l)) (ps '()) (cb #f)) (if (null? l) @@ -129,9 +128,7 @@ (define (period->string p) (sprintf "~A..~A" (month->string (car p)) - (if (cdr p) - (month->string (cdr p)) - "****-**"))) + (month->string (cdr p)))) ;; Returns a string representing a list of periods. (define (periods->string ps) @@ -139,7 +136,7 @@ (map period->string ps) ", ")) - ;; Finds a period the month marthes and returns it. If no period + ;; Finds a period the month matches and returns it. If no period ;; matches, it returns #f. (define (periods-match ps . ml) (let ((m (if (null? ml) (*current-month*) (car ml))))