(define-module (datetime) :export (date? year month day hour minute second time? datetime?) ;; To resolve colision with cadr-second from srfi-1 :replace (second) :use-module (srfi srfi-1) :use-module (srfi srfi-9) :use-module (srfi srfi-9 gnu) :use-module ((hnh util) :select (vector-last define*-public set! -> ->> swap case* set span-upto let* set->)) :use-module (srfi srfi-41) :use-module (ice-9 i18n) :use-module (ice-9 format) :use-module (ice-9 regex) :use-module (calp util config) :re-export (locale-month locale-month-short)) ;;; Enums (define-public jan 1) (define-public january 1) (define-public feb 2) (define-public february 2) (define-public mar 3) (define-public mars 3) (define-public apr 4) (define-public april 4) (define-public may 5) (define-public jun 6) (define-public june 6) (define-public jul 7) (define-public july 7) (define-public aug 8) (define-public august 8) (define-public sep 9) (define-public september 9) (define-public oct 10) (define-public october 10) (define-public nov 11) (define-public november 11) (define-public dec 12) (define-public december 12) (define-public sun 0) (define-public sunday 0) (define-public mon 1) (define-public monday 1) (define-public tue 2) (define-public tuesday 2) (define-public wed 3) (define-public wednesday 3) (define-public thu 4) (define-public thursday 4) (define-public fri 5) (define-public friday 5) (define-public sat 6) (define-public saturday 6) ;;; Configuration (define-public week-start (make-parameter sun)) (define-config week-start sun description: "First day of week" pre: (ensure (lambda (x) (<= sun x sat))) post: week-start) ;;; RECORD TYPES ;;; DATE (define-immutable-record-type (make-date year month day) date? (year year) (month month) (day day)) (define*-public (date key: (year 0) (month 0) (day 0)) (make-date year month day)) (set-record-type-printer! (lambda (r p) (catch 'misc-error (lambda () (display (date->string r "#~Y-~m-~d") p)) (lambda (err _ fmt args . rest) (format p "#< BAD year=~s month=~s day=~s>" (year r) (month r) (day r)))))) ;;; TIME (define-immutable-record-type