[m-rev.] Re: for review: new calendar standard library module
Ian MacLarty
maclarty at csse.unimelb.edu.au
Thu Feb 5 10:15:18 AEDT 2009
On Mon, Feb 02, 2009 at 01:26:02PM +1100, Ian MacLarty wrote:
> Here is a new version of the calendar module for review.
>
After a chat with Julien I've committed this with the following
additional interdiff:
diff -u library/calendar.m library/calendar.m
--- library/calendar.m 2 Feb 2009 03:01:07 -0000
+++ library/calendar.m 4 Feb 2009 22:56:33 -0000
@@ -117,6 +117,14 @@
%
:- pred current_utc_time(date::out, io::di, io::uo) is det.
+ % Calculate the Julian day number for a date on the Gregorian calendar.
+ %
+:- func julian_day_number(date) = int.
+
+ % Returns 1970/01/01 00:00:00.
+ %
+:- func unix_epoch = date.
+
% A period of time measured in years, months, days, hours, minutes,
% seconds and microseconds. Internally a duration is represented
% using only months, days, seconds and microseconds components.
@@ -817,10 +825,8 @@
Hour1 = DateB ^ dt_hour - !.Borrow,
Hour2 = DateA ^ dt_hour,
subtract_ints_with_borrow(24, Hour1, Hour2, Hours, !:Borrow),
- JDN1 = julian_day(DateB ^ dt_year, DateB ^ dt_month,
- DateB ^ dt_day),
- JDN2 = julian_day(DateA ^ dt_year, DateA ^ dt_month,
- DateA ^ dt_day),
+ JDN1 = julian_day_number(DateB),
+ JDN2 = julian_day_number(DateA),
Days = JDN1 - !.Borrow - JDN2,
Duration = init_duration(0, 0, Days, Hours, Minutes, Seconds,
MicroSeconds)
@@ -929,13 +935,11 @@
%
day_of_week(Date) = DayOfWeek :-
- JDN = julian_day(Date ^ dt_year, Date ^ dt_month, Date ^ dt_day),
+ JDN = julian_day_number(Date),
Mod = JDN mod 7,
DayOfWeek = det_day_of_week_from_mod(Mod).
-:- func julian_day(int, int, int) = int.
-
-julian_day(Year, Month, Day) = JDN :-
+julian_day_number(date(Year, Month, Day, _, _, _, _)) = JDN :-
A = (14 - Month) div 12,
Y = Year + 4800 - A,
M = Month + 12 * A - 3,
@@ -1087,6 +1091,8 @@
day_of_week_num(saturday, 5).
day_of_week_num(sunday, 6).
+unix_epoch = date(1970, 1, 1, 0, 0, 0, 0).
+
%-----------------------------------------------------------------------------%
:- end_module calendar.
%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list