このディレクトリの索引
#  http://stackoverflow.com/questions/7537380
#  Let's say i have a structure comparetime(hours,mins), when a user keys
#  example comparetime(10,40) ,
#  the structure will make comparison on a time range specified example timing entered
#  1) from 10:00 to 12:00 will print a message and
#  2) from 18:00 to 20:00 will print a message .
#  if the time keyed is not inside the range, it will also print a message.
#  
#  how can I do this ?
#  
#  it's easy to compare words but i'm really having a tough time with comparing time.

comparetime(=,_時,_分,_時,_分) :-
        integer(_時),
        integer(_分).
comparetime(=,_時,_分,_時,_分) :-
        var(_時),
        integer(_分),
        for(0,_時,23).
comparetime(=,_時,_分,_時,_分) :-
        integer(_時),
        var(_分),
        for(0,_分,59).
comparetime(=,_時,_分,_時,_分) :-
        var(_時),
        var(_分),
        for(0,_時,23),
        for(0,_分,59).

comparetime(=<,_時_1,_分_1,_時_2,_分_2) :-
        for(0,_時_1,23),
        for(0,_時_2,23),
        for(0,_分_1,59),
        for(0,_分_2,59),
        comparetime_2(=<,_時_1,_時_2,_分_1,_分_2).
comparetime(>=,_時_1,_分_1,_時_2,_分_2) :-
        for(0,_時_1,23),
        for(0,_時_2,23),
        for(0,_分_1,59),
        for(0,_分_2,59),
        comparetime_2(>=,_時_1,_時_2,_分_1,_分_2).

comparetime(<,_時_1,_分_1,_時_2,_分_2) :-
        comparetime(=<,_時_1,_分_1,_時_2,_分_2),
        \+((_時_1 = _時_2,_分_1 = _分_2)).
comparetime(>,_時_1,_分_1,_時_2,_分_2) :-
        comparetime(>=,_時_1,_分_1,_時_2,_分_2),
        \+((_時_1 = _時_2,_分_1 = _分_2)).

comparetime_2(=<,_時,_時,_分_1,_分_2) :-
        _分_1 =< _分_2.
comparetime_2(=<,_時_1,_時_2,_分_1,_分_2) :-
        _時_1 < _時_2.
comparetime_2(>=,_時,_時,_分_1,_分_2) :-
        _分_1 >= _分_2.
comparetime_2(>=,_時_1,_時_2,_分_1,_分_2) :-
        _時_1 > _時_2.