I want to compare two date structures that return true if the first date is earlier than the second one, and false otherwise.
The logic is simple.
Let the first date D1, and second date D2.
- If year of D1 > year of D2, return
false. - If year of D1 == year of D2, compare month.
- If year of D1 < year of D2, return
true.
This process is repeated till the comparison of seconds.
Sample code I tried:
date_earlier_than(date(SY, SM, SD, SH, SMm, SS, _, _, _),
date(EY, EM, ED, EH, EMm, ES, _, _, _)) :-
( SY > EY ->
fail
;
SY =:= EY ->
( SM > EM ->
fail
;
SM =:= EM ->
( SD > ED ->
fail
;
SD =:= ED ->
( SH > EH ->
fail
;
SH =:= EH ->
( SMm > EMm ->
fail
;
SMm =:= EMm ->
( SS >= ES ->
fail
;
true
)
;
true
)
;
true
)
;
true
)
;
true
)
;
true
).
This predicate always returns false whatever dates passed as arguments.
I don't know where it goes wrong, and even if I use trace to keep track of the process, the predicate immediately returns false after the execution.
Aucun commentaire:
Enregistrer un commentaire