mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
The date/0 type is misnamed. Values of the type have both a date and a time
component. The common name for combined date and time values is a "date_time",
for which we have had a type synonym since 2014. This change makes date_time
the proper name for type and make date into the type synonym.
Deprecate the date/0 name and note that we will change its meaning in a future
release. (It will eventually be used for data values that do not have a time
component.)
Rename predicates and functions accordingly and mark the existing versions as
obsolete.
library/calendar.m:
Make the above renamings.
library/hard_coded/stream.string_writer.m:
Replace a call to a now obsolete function.
NEWS.md:
Add entry describing the above.
tests/hard_coded/calendar_init_date.{m,exp}:
tests/hard_coded/calendar_test.m:
tests/hard_coded/fold_days.m:
tests/hard_coded/stream_string_writer_types.m:
Conform to the above changes.
69 lines
2.4 KiB
Mathematica
69 lines
2.4 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
:- module fold_days.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module calendar.
|
|
:- import_module int.
|
|
:- import_module string.
|
|
|
|
main(!IO) :-
|
|
% Test 1: 1900 was not a leap year.
|
|
Date1A = det_init_date_time(1900, february, 25, 0, 0, 0, 0),
|
|
Date1B = det_init_date_time(1900, march, 1, 0, 0, 0, 0),
|
|
io.write_string("Test 1:\n", !IO),
|
|
foldl_days(write_date_time, Date1A, Date1B, !IO),
|
|
io.nl(!IO),
|
|
|
|
% Test 2: 2000 was a leap year.
|
|
Date2A = det_init_date_time(2000, february, 25, 0, 0, 0, 0),
|
|
Date2B = det_init_date_time(2000, march, 1, 0, 0, 0, 0),
|
|
io.write_string("Test 2:\n", !IO),
|
|
foldl_days(write_date_time, Date2A, Date2B, !IO),
|
|
io.nl(!IO),
|
|
|
|
% Test 3: 1977 was not a leap year.
|
|
Date3A = det_init_date_time(1977, february, 25, 0, 0, 0, 0),
|
|
Date3B = det_init_date_time(1977, march, 1, 0, 0, 0, 0),
|
|
io.write_string("Test 3:\n", !IO),
|
|
foldl_days(write_date_time, Date3A, Date3B, !IO),
|
|
io.nl(!IO),
|
|
|
|
% Test 4: calendar dates of start and end are the same,
|
|
% time of start is less than that of the end.
|
|
Date4A = det_init_date_time(1977, february, 17, 0, 0, 0, 0),
|
|
Date4B = det_init_date_time(1977, february, 17, 1, 0, 0, 0),
|
|
io.write_string("Test 4:\n", !IO),
|
|
foldl_days(write_date_time, Date4A, Date4B, !IO),
|
|
io.nl(!IO),
|
|
|
|
% Test 5: calendar dates of start and end are the same,
|
|
% time of start is equal to that of the end.
|
|
Date5A = det_init_date_time(1977, february, 17, 0, 0, 0, 0),
|
|
Date5B = det_init_date_time(1977, february, 17, 0, 0, 0, 0),
|
|
io.write_string("Test 5:\n", !IO),
|
|
foldl_days(write_date_time, Date5A, Date5B, !IO),
|
|
io.nl(!IO),
|
|
|
|
% Test 6: calendar dates of start and end are the same,
|
|
% time of the start is greater than that of the end.
|
|
Date6A = det_init_date_time(1977, february, 17, 1, 0, 0, 0),
|
|
Date6B = det_init_date_time(1977, february, 17, 0, 0, 0, 0),
|
|
io.write_string("Test 6:\n", !IO),
|
|
foldl_days(write_date_time, Date6A, Date6B, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- pred write_date_time(date_time::in, io::di, io::uo) is det.
|
|
|
|
write_date_time(DateTime, !IO) :-
|
|
Str = date_time_to_string(DateTime),
|
|
io.write_string(Str ++ "\n", !IO).
|