You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
(define-module (tk mcron)
|
|
#:export (sec/min sec/hour sec/day sec/week
|
|
sec/mins sec/hours sec/days sec/weeks
|
|
step-from
|
|
str->secs
|
|
strf->secs
|
|
)
|
|
#:use-module (srfi srfi-19)
|
|
#:duplicates (warn-override-core warn))
|
|
|
|
(define sec/min 60)
|
|
(define sec/hour (* 60 sec/min))
|
|
(define sec/day (* 24 sec/hour))
|
|
(define sec/week (* 7 sec/day))
|
|
|
|
(define (sec/mins n) (* n sec/min))
|
|
(define (sec/hours n) (* n sec/hour))
|
|
(define (sec/days n) (* n sec/day))
|
|
(define (sec/weeks n) (* n sec/week))
|
|
|
|
;; Format here refers to the format found in srfi-19 (Ref: 7.5.16.6)
|
|
;; Literally just conversions out of (string->date)
|
|
(define (strf->secs str format)
|
|
(time-second (date->time-utc (string->date str format))))
|
|
|
|
(define (str->secs str)
|
|
(strf->secs str "~Y~m~d~H~M~S"))
|
|
|
|
;; Normalize the time tm to be the next step sized increment from base.
|
|
;; All time arguments are expected to be a time in seconds
|
|
(define (step-from base step tm)
|
|
(let ((steps (euclidean-quotient (- tm base) step)))
|
|
(+ base (* step (+ 1 steps)))))
|
|
|
|
;;;;;;;;;;;;;;;;;;;
|
|
;; Logging Utility
|
|
(define (current-date-string)
|
|
(let ((ct (current-time)))
|
|
(string-append (number->string (date-year ct)) "-"
|
|
(number->string (date-month ct)) "-"
|
|
(number->string (date-day ct)))))
|
|
|
|
(define (yesterday-date-string)
|
|
(let* ((day (make-time time-duration 0 sec/day))
|
|
(ct (subtract-duration! (current-time) day)))
|
|
(string-append (number->string (date-year ct)) "-"
|
|
(number->string (date-month ct)) "-"
|
|
(number->string (date-day ct)))))
|
|
;;;;;;;;;;;;;;;;;;;
|