-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdate.pro
More file actions
29 lines (23 loc) · 784 Bytes
/
Copy pathdate.pro
File metadata and controls
29 lines (23 loc) · 784 Bytes
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
:- module(date, [
date_compare/3
, date_before/2
, date_equal/2
, date_after/2
]).
:- use_module(library(clpfd)).
/*
This assumes that the date is valid.
If you don't want to this, you can also compare dates with the standard order of terms @</2.
*/
date_before(date(Y0, M0, D0), date(Y1, M1, D1)) :-
Y0 #< Y1
; Y0 #=< Y1, M0 #< M1
; Y0 #=< Y1, M0 #=< M1, D0 #< D1.
date_after(A, B) :- date_before(B, A).
date_equal(date(Y, M, D), date(Y, M, D)).
% date_compare(Operator, Date_0, Date_1).
date_compare('<', A, B) :- date_before(A, B).
date_compare('=<', A, B) :- date_before(A, B); date_equal(A, B).
date_compare('>', A, B) :- date_after(A, B).
date_compare('>=', A, B) :- date_after(A, B); date_equal(A, B).
date_compare('=', A, B) :- date_equal(A, B).