◊(Local Yarn Code "Check-in [28ee8201]")

Overview
Comment:Add ymd->dateformat and add unit tests
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 28ee8201919be2bfff2db1edc0501bf7f490e219164a5ce274d5f975c37c21df
User & Date: joel on 2018-08-12 16:31:34
Other Links: manifest | tags
Context
2018-08-22
02:45
Correct unit test in dates.rkt check-in: 6034c1b0 user: joel tags: trunk
2018-08-12
16:31
Add ymd->dateformat and add unit tests check-in: 28ee8201 user: joel tags: trunk
2018-08-09
22:40
Add license to CSS check-in: c7616fe6 user: joel tags: trunk
Changes

Modified dates.rkt from [9a276406] to [6947cc76].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31



32

33













;; limitations under the License.
;;
;; Author contact information:
;;   joel@jdueck.net
;;   https://joeldueck.com
;; -------------------------------------------------------------------------

;; Convenience functions for date strings

(require gregor
         racket/string)

(provide (all-defined-out))

;; Ignores everything after the first space



(define (ymd->english ymd-string)

  (~t (iso8601->date (car (string-split ymd-string))) "MMMM d, yyyy"))




















|






|
>
>
>

>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;; limitations under the License.
;;
;; Author contact information:
;;   joel@jdueck.net
;;   https://joeldueck.com
;; -------------------------------------------------------------------------

;; Convenience functions for YYYY-MM-DD date strings

(require gregor
         racket/string)

(provide (all-defined-out))

;; These functions ignore everything after the first space!
(define (ymd->dateformat ymd-string dateformat)
  (~t (iso8601->date (car (string-split ymd-string))) dateformat))

(define (ymd->english ymd-string)
  (ymd->dateformat ymd-string "MMMM d, yyyy"))

(module+ test
  (require rackunit)
  (check-equal? (ymd->english "2018-08-12") "August 12, 2018")
  (check-equal? (ymd->dateformat "2018-08-12" "d MMM YYYY") "12 Aug 2018")

  ;; How we handle weird input
  (check-equal? (ymd->english "2018-08-12 everything after 1st space ignored") "August 12, 2018")
  (check-equal? (ymd->english "2018-08 omitting the day") "August 1, 2018")
  (check-equal? (ymd->english "2018 omitting month and day") "January 1, 2018")
  (check-equal? (ymd->dateformat "2018-08-12") "123")

  ;; Stuff we just don't handle
  (check-exn exn:gregor:parse? (lambda () (ymd->english "2018-xyz"))))