From 245d668c0a9df764cf2d1f7ae8a3e9ee169a670a Mon Sep 17 00:00:00 2001 From: Brady McDonough Date: Wed, 27 Jan 2021 05:48:28 -0700 Subject: [PATCH] Added mcron util --- tk/Makefile | 2 +- tk/mcron.scm | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tk/mcron.scm diff --git a/tk/Makefile b/tk/Makefile index 559a5d8..bd79cbd 100644 --- a/tk/Makefile +++ b/tk/Makefile @@ -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) diff --git a/tk/mcron.scm b/tk/mcron.scm new file mode 100644 index 0000000..4c56f25 --- /dev/null +++ b/tk/mcron.scm @@ -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)))))