The synodic month, or complete cycle of phases of the Moon as seen from Earth, averages 29.530588 mean solar days in length. The cycle was used by Meton (fl. 432 BC), an Athenian astronomer for a luni‐solar calendar. We use epoch time in milliseconds as input to our calcula-tions and calculate the moon phase as follows where 86400000 = 24*60*60*1000, i.e. the number of milliseconds in one day:
% phase(+Integer, -Float)
phase(T, N) :-
D is T/86400000,
P is (D - 6.5)/29.5305882,
N is (P-truncate(P))*8.
A German description of the moon phase can be extracted by the following table and Prolog code:
% descr(+Integer, -Atom)
descr(1, R) :- !, R = 'Zunehmender Sichelmond'.
descr(2, R) :- !, R = 'Zunehmend Halbmond'.
descr(3, R) :- !, R = 'Zunehmend Dreiviertelmond'.
descr(4, R) :- !, R = 'Vollmond'.
descr(5, R) :- !, R = 'Abnehmend Dreiviertelmond'.
descr(6, R) :- !, R = 'Abnehmend Halbmond'.
descr(7, R) :- !, R = 'Abnehmend Sichelmond'.
descr(_, 'Neumond').
A Prolog query then gives us, where the wall statistics key gives us epoch time in milliseconds:
?- statistics(wall, T), phase(T, P),
K is truncate(P+0.5), descr(K, D).
T = 1706027531173, P = 3.4556983476595633,
K = 3, D = 'Zunehmend Dreiviertelmond'.
We are now going to wrap the Prolog query into a HTML page reachable through a HTTP server. The HTTP server will do the computation and produce some HTML markup for a visualization.