root/tags/lgt2310/library/date.lgt

Revision 3688, 1.5 KB (checked in by pmoura, 21 months ago)

Code reformating.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- object(date,
3    implements(datep)).
4
5    :- info([
6        version is 1.1,
7        author is 'Paulo Moura',
8        date is 2006/3/7,
9        comment is 'Date predicates.']).
10
11    today(Year, Month, Day) :-
12        {'$lgt_current_date'(Year, Month, Day)}.
13
14    leap_year(Year) :-
15        (   0 =:= mod(Year, 4), 0 =\= mod(Year, 100) ->
16            true
17        ;   0 =:= mod(Year, 400)
18        ).
19
20    name_of_day(1, 'Sunday', 'Sun').
21    name_of_day(2, 'Monday', 'Mon').
22    name_of_day(3, 'Tuesday', 'Tue').
23    name_of_day(4, 'Wednesday', 'Wed').
24    name_of_day(5, 'Thursday', 'Thu').
25    name_of_day(6, 'Friday', 'Fri').
26    name_of_day(7, 'Saturday', 'Sat').
27
28    name_of_month( 1, 'January', 'Jan').
29    name_of_month( 2, 'February', 'Feb').
30    name_of_month( 3, 'March', 'Mar').
31    name_of_month( 4, 'April', 'Apr').
32    name_of_month( 5, 'May', 'May').
33    name_of_month( 6, 'June', 'Jun').
34    name_of_month( 7, 'July', 'Jul').
35    name_of_month( 8, 'August', 'Aug').
36    name_of_month( 9, 'September', 'Sep').
37    name_of_month(10, 'October', 'Oct').
38    name_of_month(11, 'November', 'Nov').
39    name_of_month(12, 'December', 'Dec').
40
41    days_in_month( 1, _, 31).
42    days_in_month( 2, Year, Days) :-
43        leap_year(Year) -> Days = 29; Days = 28.
44    days_in_month( 3, _, 31).
45    days_in_month( 4, _, 30).
46    days_in_month( 5, _, 31).
47    days_in_month( 6, _, 30).
48    days_in_month( 7, _, 31).
49    days_in_month( 8, _, 31).
50    days_in_month( 9, _, 30).
51    days_in_month(10, _, 31).
52    days_in_month(11, _, 30).
53    days_in_month(12, _, 31).
54
55    valid(Year, Month, Day) :-
56        integer(Year),
57        integer(Month), Month >= 1, Month =< 12,
58        integer(Day),
59        days_in_month(Month, Year, Days),
60        Day >= 1, Day =< Days.
61
62:- end_object.
Note: See TracBrowser for help on using the browser.