d1a8c23e62
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@562 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
72 lines
1.5 KiB
Plaintext
72 lines
1.5 KiB
Plaintext
|
|
:- object(date,
|
|
implements(datep)).
|
|
|
|
|
|
:- info([
|
|
version is 1.0,
|
|
authors is 'Paulo Moura',
|
|
date is 2000/7/24,
|
|
comment is 'Date predicates.']).
|
|
|
|
|
|
today(Year, Month, Day) :-
|
|
{'$lgt_current_date'(Year, Month, Day)}.
|
|
|
|
|
|
leap_year(Year) :-
|
|
(0 is mod(Year, 4),
|
|
\+ 0 is mod(Year, 100)
|
|
;
|
|
0 is mod(Year, 400)),
|
|
!.
|
|
|
|
|
|
name_of_day(1, 'Sunday', 'Sun').
|
|
name_of_day(2, 'Monday', 'Mon').
|
|
name_of_day(3, 'Tuesday', 'Tue').
|
|
name_of_day(4, 'Wednesday', 'Wed').
|
|
name_of_day(5, 'Thursday', 'Thu').
|
|
name_of_day(6, 'Friday', 'Fri').
|
|
name_of_day(7, 'Saturday', 'Sat').
|
|
|
|
|
|
name_of_month( 1, 'January', 'Jan').
|
|
name_of_month( 2, 'February', 'Feb').
|
|
name_of_month( 3, 'March', 'Mar').
|
|
name_of_month( 4, 'April', 'Apr').
|
|
name_of_month( 5, 'May', 'May').
|
|
name_of_month( 6, 'June', 'Jun').
|
|
name_of_month( 7, 'July', 'Jul').
|
|
name_of_month( 8, 'August', 'Aug').
|
|
name_of_month( 9, 'September', 'Sep').
|
|
name_of_month(10, 'October', 'Oct').
|
|
name_of_month(11, 'November', 'Nov').
|
|
name_of_month(12, 'December', 'Dec').
|
|
|
|
|
|
days_in_month( 1, _, 31).
|
|
days_in_month( 2, Year, Days) :-
|
|
leap_year(Year) -> Days = 29; Days = 28.
|
|
days_in_month( 3, _, 31).
|
|
days_in_month( 4, _, 30).
|
|
days_in_month( 5, _, 31).
|
|
days_in_month( 6, _, 30).
|
|
days_in_month( 7, _, 31).
|
|
days_in_month( 8, _, 31).
|
|
days_in_month( 9, _, 30).
|
|
days_in_month(10, _, 31).
|
|
days_in_month(11, _, 30).
|
|
days_in_month(12, _, 31).
|
|
|
|
|
|
valid(Year, Month, Day) :-
|
|
integer(Year),
|
|
integer(Month), Month >= 1, Month =< 12,
|
|
integer(Day),
|
|
days_in_month(Month, Year, Days),
|
|
Day >= 1, Day =< Days.
|
|
|
|
|
|
:- end_object.
|