diff --git a/projects/sched/build.hxml b/projects/sched/build.hxml new file mode 100644 index 00000000..b5621aa8 --- /dev/null +++ b/projects/sched/build.hxml @@ -0,0 +1,4 @@ +-lib kiss +-cp src +--main sched.Main +--interp \ No newline at end of file diff --git a/projects/sched/haxelib.json b/projects/sched/haxelib.json new file mode 100644 index 00000000..0d05821e --- /dev/null +++ b/projects/sched/haxelib.json @@ -0,0 +1,17 @@ +{ + "main": "sched.Main", + "name": "sched", + "description": "barebones schedule-maker", + "classPath": "src/", + "dependencies": { + "kiss": "" + }, + "url": "https://github.com/NQNStudios/kisslang", + "contributors": [ + "NQNStudios" + ], + "version": "0.0.0", + "releasenote": "", + "tags": [], + "license": "LGPL" +} \ No newline at end of file diff --git a/projects/sched/src/sched/Main.hx b/projects/sched/src/sched/Main.hx new file mode 100644 index 00000000..62e13048 --- /dev/null +++ b/projects/sched/src/sched/Main.hx @@ -0,0 +1,23 @@ +package sched; + +import kiss.Kiss; +import kiss.Prelude; + +enum AMPM { + AM; + PM; +} + +enum Time { + Time(hour:Int, minute:Int, ampm:AMPM); +} + +typedef ScheduleEntry = { + start:Time, + text:String +} + +typedef Schedule = Array; + +@:build(kiss.Kiss.build()) +class Main {} diff --git a/projects/sched/src/sched/Main.kiss b/projects/sched/src/sched/Main.kiss new file mode 100644 index 00000000..f72bf56f --- /dev/null +++ b/projects/sched/src/sched/Main.kiss @@ -0,0 +1,63 @@ +(function :Time currentTime [] + (let [now (Date.now) + &mut ampm AM] + (Time + (case (now.getHours) + (0 12) + (12 + (set ampm PM) + 12) + ((when (> hours 12) hours) + (set ampm PM) + (- hours 12)) + (hours hours)) + (now.getMinutes) + ampm))) + +(function :Int sortIndex [time] + (case time + ((Time 12 minute AM) minute) + ((Time hour minute AM) (+ minute (* 60 hour))) + ((Time 12 minute PM) (+ minute (* 60 12))) + ((Time hour minute PM) (+ minute (* 60 (+ hour 12)))))) + +(function isBefore [time1 time2] + (< (sortIndex time1) (sortIndex time2))) + +(function isAfter [time1 time2] + !(isBefore time1 time2)) + +(defMacro simpleSchedule [&body args] + `[,@(for [startTime text] (groups args 2 Throw) + `(object + start ,startTime + text ,text))]) + +(var sampleSchedule + (simpleSchedule + (Time 8 0 AM) "Coffee & shower" + (Time 8 30 AM) "Breakfast" + (Time 9 0 AM) "Writing or piano" + (Time 10 0 AM) "Morning captures" + (Time 11 0 AM) "Break" + (Time 12 0 PM) "Lunch" + (Time 1 0 PM) "After-lunch work" + (Time 2 0 PM) "Break" + (Time 3 0 PM) "After break work" + (Time 5 0 PM) "Chill out")) + +// Count midnight as the first hour of the day +(assert (isBefore (Time 12 0 AM) (Time 12 0 PM))) +(assert (isBefore (Time 11 59 AM) (Time 12 0 PM))) + +(function currentEntry [schedule] + (let [now (currentTime)] + (doFor [event nextEvent] (pairs schedule) + (when (and (isAfter now event.start) (isBefore now nextEvent.start)) + (return event.text))) + (when (isAfter now .start (nth schedule -1)) + (return .text (nth schedule -1)))) + "Nothing scheduled right now") + +(print (currentTime)) +(print (currentEntry sampleSchedule)) \ No newline at end of file diff --git a/projects/sched/test.sh b/projects/sched/test.sh new file mode 100644 index 00000000..0ee8ae95 --- /dev/null +++ b/projects/sched/test.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +haxe build.hxml \ No newline at end of file