forked from fnogatz/date_time
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.pl
52 lines (44 loc) · 1.36 KB
/
test.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
:- use_module(library(date_time)).
term_expansion(Query -> Result, (Head :- Test)) :-
format(atom(Head), '~w -> ~w', [Query, Result]),
Test = (
call(Query),
call(Result),
!
),
tap:register_test(Head).
:- use_module(library(tap)).
% Real tests go here
date_compare(date(2002,1,15), X, date(2002,2,24)) ->
X = (<).
date_compare(date(2002,1,15), =<, date(2002,2,24)) ->
true.
date_add(date(2002,1,15), [1 months, 2 days], D) ->
D = date(2002, 2, 17).
date_add(date(2002,1,15), [1 years, 1 months, 15 days], D) ->
D = date(2003, 3, 2).
date_add(date(2002,1,31), 1 months, X) ->
X = date(2002, 2, 28).
date_add(date(2002,2,28), 1 months, X) ->
X = date(2002, 3, 31).
date_difference(date(2002,3,2), date(2002,1,15), D) ->
D = [0 years, 1 months, 15 days].
date_difference(date(2002,2,28), date(2002,1,31), X) ->
X = [0 years, 1 months, 0 days].
date_string(D, F, "24 Feb 1946") ->
D = date(1946, 2, 24),
F = 'd mon y'.
date_string(D, F, "February 24, 1946") ->
D = date(1946, 2, 24),
F = 'month d, y'.
date_string(date(1946,2,24), 'month d, y', X) ->
X = "February 24, 1946".
date_string(D, 'd/m/y', "24/2/1946") ->
D = date(1946, 2, 24).
date_string(date(1946,2,24), F, X) ->
F = 'y/m/d',
X = "1946/2/24".
time_string(time(2,33,15), X) ->
X = "2:33:15".
time_string(T, "2:33:22") ->
T = time(2, 33, 22).