Added mcron util

master
Brady McDonough 5 years ago
parent 1d1d1fafb7
commit 245d668c0a

@ -1,6 +1,6 @@
TARGET := $(shell guile -c "(display (%site-dir))")
CCACHE := $(shell guile -c "(display(%site-ccache-dir))")
OBJ := listlogic.go ports.go
OBJ := listlogic.go ports.go mcron.go
.PHONY: all clean install uninstall
all: $(OBJ)

@ -0,0 +1,33 @@
(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 (truncate-quotient (- tm base) step)))
(+ base (* step (+ 1 steps)))))
Loading…
Cancel
Save