summary refs log tree commit diff
path: root/js/moon-phase.js
blob: a8a3baeff0f1c30b777f52a83c49ca4cc8872cc4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// truncated to the day, America/Chicago time
// only includes moons through end of 2024 (brown lunation number 1262)
moons = [
19644, 19651, 19658, 19666,
19674, 19681, 19688, 19695,
19703, 19710, 19717, 19725,
19733, 19739, 19747, 19755,
19762, 19769, 19777, 19785,
19792, 19798, 19807, 19814,
19821, 19828, 19836, 19844,
19850, 19858, 19866, 19873,
19880, 19888, 19895, 19902,
19909, 19917, 19925, 19931,
19939, 19947, 19954, 19961,
19968, 19977, 19983, 19990,
19998, 20006, 20013, 20020,
20028, 20035, 20042, 20049,
20058, 20065, 20072, 20079,
20087, 20094, 20101, 20109
]
icons = ['\u{1f311}\ufe0e', '\u{1f313}\ufe0e', '\u{1f315}\ufe0e', '\u{1f317}\ufe0e']
// icons_inverted = ['\u{1f315}', '\u{1f317}', '\u{1f311}', '\u{1f313}']

function getMoonsString(date) {
	next_phase = moons.findIndex((e) => e >= date)
	next_four_phases = moons.slice(next_phase, next_phase + 4)

	str = ""

	// unrolled loop just to git er done
	str = str.concat('\u2500'.repeat(next_four_phases[0] - date))
		.concat(icons[next_phase % 4])

		.concat('\u2500'.repeat(next_four_phases[1] - next_four_phases[0] - 1))
		.concat(icons[(next_phase + 1) % 4])

		.concat('\u2500'.repeat(next_four_phases[2] - next_four_phases[1] - 1))
		.concat(icons[(next_phase + 2) % 4])

		.concat('\u2500'.repeat(next_four_phases[3] - next_four_phases[2] - 1))
		.concat(icons[(next_phase + 3) % 4])

	return str
}

document.addEventListener('DOMContentLoaded', (event) => {
	today = Math.floor((Date.now() - 18e6) / 86.4e6)
	document.getElementById('decor-moons').innerHTML = getMoonsString(today)
})