Skip to content

Commit ec4bb04

Browse files
committed
bugfixes
1 parent f0b3742 commit ec4bb04

4 files changed

Lines changed: 70 additions & 40 deletions

File tree

karma.conf.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ module.exports = function (config) {
2424
client: {
2525
args: ['shadow.test.karma.init'],
2626
singleRun: true
27-
}
27+
},
28+
pingTimeout: 60000,
29+
browserNoActivityTimeout: 1000 * 60 * 5 // minutes
2830
})
2931
}

src/witch_clock/calendar.cljs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
(def MINUTES-IN-HOUR 60)
8787
(def SECONDS-IN-MINUTE 60)
8888

89+
(defn print-date [dt]
90+
(.toLocaleString dt))
91+
8992
(defn- get-seasons [year & {:keys [southern?]}]
9093
(let [js-seasons (astro/Seasons year)
9194
js-last-seasons (astro/Seasons (dec year))
@@ -125,6 +128,7 @@
125128
(defn- compare-dates [op dt1 dt2 & dts]
126129
(apply op (map #(.getTime %) (concat [dt1 dt2] dts))))
127130
(def is-before (partial compare-dates <))
131+
(def is-or-before (partial compare-dates <=))
128132
(def is-after (partial compare-dates >))
129133
(defn days-between [days dt1 dt2]
130134
(count
@@ -253,9 +257,9 @@
253257
"The Demise")
254258
conclusion]])))
255259

256-
(defn get-day
260+
(defn get-date
257261
([witchy-year]
258-
(get-day witchy-year (new js/Date)))
262+
(get-date witchy-year (new js/Date)))
259263
([{:keys [months seasons days cycle-end nth-cycle]} dt]
260264
(cond
261265
(is-before dt (:dawn (first days)))
@@ -279,7 +283,7 @@
279283
(->> dawn-to-dawn
280284
(filter
281285
(fn [[_cycle-i [dawn _next-dawn]]]
282-
(is-before dawn dt)))
286+
(is-or-before dawn dt)))
283287
(map
284288
(fn [[cycle-i [_dawn _next-dawn]]]
285289
[(inc cycle-i) [_dawn _next-dawn]]))
@@ -315,8 +319,8 @@
315319
(->> sorted-moon-phase-dt
316320
(filter
317321
(fn [[_month _phase phase-dt]]
318-
(is-before dawn phase-dt)))
319-
last)
322+
(is-before phase-dt next-dawn)))
323+
first)
320324
[_month _phase month-dt]
321325
(->> sorted-moon-phase-dt
322326
(filter
@@ -330,7 +334,7 @@
330334
(fn [[_month _phase other-phase-dt]]
331335
(is-before phase-dt other-phase-dt)))
332336
last)
333-
phase-i (days-between dawns phase-dt dawn)
337+
phase-i (days-between dawns phase-dt next-dawn)
334338
phase-n (days-between dawns phase-dt next-phase-dt)
335339
[next-month _next-phase next-month-dt]
336340
(if (not= month next-month*)
@@ -342,7 +346,7 @@
342346
(is-before month-dt next-month-dt)
343347
(not= month next-month))))
344348
last))
345-
month-i (days-between dawns month-dt dawn)
349+
month-i (days-between dawns month-dt next-dawn)
346350
month-n (days-between dawns month-dt next-month-dt)]
347351
{:cycle [nth-cycle (inc cycle-i) cycle-n]
348352
:season [season season-dt (inc season-i) season-n]

src/witch_clock/web.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
(refresh-seasons! year)
5858
(refresh-months! year)
5959
(when year
60-
(reset! -date (calendar/get-day year))))
60+
(reset! -date (calendar/get-date year))))
6161

6262
(defn track-time! [-geo -year -date -time -time-timer]
6363
(when @-time-timer
@@ -73,7 +73,7 @@
7373
witchy-year (calendar/from-gregorian-year year latitude longitude)]
7474
(reset! -year witchy-year))
7575
(calendar/is-before (-> @-date :day (nth 2)) now)
76-
(reset! -date (calendar/get-day @-year now))
76+
(reset! -date (calendar/get-date @-year now))
7777
:else
7878
(reset! -time (calendar/get-current-time @-date)))))
7979
(* 3 1000))))

test/witch_clock/core_test.cljs

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,60 @@
11
(ns witch-clock.core-test
22
(:require
33
[clojure.string :as string]
4-
[clojure.test :refer [deftest is testing]]
4+
[clojure.test :refer [is testing deftest]]
55
[witch-clock.calendar :as calendar]))
66

77
(deftest witch-clock-sanity-test
8-
(testing "Works for one hundred years."
9-
(doseq [[latitude longitude]
10-
[[45.5761 -122.6881] ; north america
11-
[25.2744 133.7751] ; australia
12-
]]
13-
(doseq [i (range 100)
14-
:let [greg-year (+ calendar/FIRST-CYCLE-YEAR i -50)
15-
{:keys [nth-cycle months seasons conclusion cycle-end days]}
16-
(calendar/from-gregorian-year greg-year latitude longitude)]]
17-
(is (number? nth-cycle))
18-
(doseq [month calendar/MONTHS
19-
:when (get months month)
20-
:let [i (inc (.indexOf calendar/MONTHS month))
21-
next-month (nth calendar/MONTHS i nil)
22-
[new-moon waxing-moon full-moon waning-moon] (map :date (get months month))]]
23-
(is (calendar/is-before new-moon waxing-moon full-moon waning-moon))
24-
(if (get months next-month)
25-
(let [next-new-moon (-> months next-month first :date)]
26-
(is (calendar/is-before waning-moon next-new-moon)))
27-
(is (calendar/is-before waning-moon cycle-end))))
28-
(doseq [season calendar/SEASONS
29-
:let [next-season (get calendar/NEXT-SEASON season)]]
30-
(is (calendar/is-before (get seasons season) (get seasons next-season))))
31-
(is (calendar/is-before conclusion cycle-end))
32-
(doseq [[day next-day] (zipmap (drop-last 1 days) (drop 1 days))]
33-
(is (calendar/is-before (:dawn day) (:dusk day) (:dawn next-day) (:dusk next-day))
34-
(->> [(:dawn day) (:dusk day) (:dawn next-day) (:dusk next-day)]
35-
(map #(.toLocaleString %))
36-
(string/join ", "))))))))
8+
(doseq [greg-year (map #(+ calendar/FIRST-CYCLE-YEAR % -5) (range 10))
9+
[latitude longitude]
10+
[[45.5761 -122.6881] ; north america
11+
[25.2744 133.7751] ; australia
12+
]]
13+
(let [{:keys [nth-cycle months seasons conclusion cycle-end days]
14+
:as witchy-year}
15+
(calendar/from-gregorian-year greg-year latitude longitude)]
16+
(println (str "Testing: " (string/join " ; " [greg-year latitude longitude])))
17+
(is (number? nth-cycle))
18+
(doseq [month calendar/MONTHS
19+
:when (get months month)
20+
:let [i (inc (.indexOf calendar/MONTHS month))
21+
next-month (nth calendar/MONTHS i nil)
22+
[new-moon waxing-moon full-moon waning-moon] (map :date (get months month))]]
23+
(is (calendar/is-before new-moon waxing-moon full-moon waning-moon))
24+
(if (get months next-month)
25+
(let [next-new-moon (-> months next-month first :date)]
26+
(is (calendar/is-before waning-moon next-new-moon)))
27+
(is (calendar/is-before waning-moon cycle-end))))
28+
(doseq [season calendar/SEASONS
29+
:let [next-season (get calendar/NEXT-SEASON season)]]
30+
(is (calendar/is-before (get seasons season) (get seasons next-season))))
31+
(is (calendar/is-before conclusion cycle-end))
32+
(doseq [[day next-day] (zipmap (drop-last 1 days) (drop 1 days))
33+
:let [date (calendar/get-date witchy-year (:dawn day))
34+
next-date (calendar/get-date witchy-year (:dawn next-day))]]
35+
(is (calendar/is-before (:dawn day) (:dusk day) (:dawn next-day) (:dusk next-day))
36+
(->> [(:dawn day) (:dusk day) (:dawn next-day) (:dusk next-day)]
37+
(map #(.toLocaleString %))
38+
(string/join ", ")))
39+
(is (apply calendar/is-or-before (concat (:day date) (:day next-date))))
40+
(let [[month _month-dt month-i :as today-month] (:month date)
41+
[tmrw-month _tmrw-month-dt tmrw-month-i :as tmrw-month*] (:month next-date)]
42+
(if (= month tmrw-month)
43+
(is (= (inc month-i) tmrw-month-i)
44+
(str [today-month tmrw-month*]))
45+
(is (= 1 tmrw-month-i)
46+
(str tmrw-month*))))
47+
(let [[phase _phase-dt phase-i :as today-phase] (:phase date)
48+
[tmrw-phase _tmrw-phase-dt tmrw-phase-i :as tmrw-phase*] (:phase next-date)]
49+
(if (= phase tmrw-phase)
50+
(is (= (inc phase-i) tmrw-phase-i)
51+
(str [today-phase tmrw-phase*]))
52+
(is (= 1 tmrw-phase-i)
53+
(str tmrw-phase*))))
54+
(let [[season _season-dt season-i :as today-season] (:season date)
55+
[tmrw-season _tmrw-season-dt tmrw-season-i :as tmrw-season*] (:season next-date)]
56+
(if (= season tmrw-season)
57+
(is (= (inc season-i) tmrw-season-i)
58+
(str [today-season tmrw-season*]))
59+
(is (= 1 tmrw-season-i)
60+
(str tmrw-season*))))))))

0 commit comments

Comments
 (0)