Skip to content

Instantly share code, notes, and snippets.

@mndrix
Last active December 15, 2015 00:29
Show Gist options
  • Save mndrix/5173377 to your computer and use it in GitHub Desktop.
Save mndrix/5173377 to your computer and use it in GitHub Desktop.
Modified Julian Day calculations in Prolog. This experiment might form the basis of a date library someday.
:- module(julian, [calendar/2]).
:- use_module(library(clpfd)).
calendar(datetime(MJD,_Nano), gregorian(Year, Month, Day)) :-
A #= (14-Month)/12,
Y #= Year + 4800 - A,
M #= Month + 12*A - 3,
MJD #= Day + (153*M+2)/5 + (Y*3652425/10000) - 2432046.
@mndrix
Copy link
Author

mndrix commented Mar 16, 2013

Find Fourth of July on a Sunday during Dwight Eisenhower's presidency:

?- use_module(library(clpfd)).
true.
?- Y in 1953..1961, date_name(Dt, (sunday,july_fourth,gregorian(Y,_,_))).
Y = 1954,
Dt = datetime(34927, _G44).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment