Finish period documentation, cleanup period usage.
This commit is contained in:
parent
9385745cf7
commit
4196e95118
3 changed files with 41 additions and 14 deletions
43
README.md
43
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
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue