From b8dde054b2dd2e28ca4c5af563850761ac684c9f Mon Sep 17 00:00:00 2001 From: joewatt95 Date: Wed, 11 Oct 2023 17:31:07 +0800 Subject: [PATCH] more fixes --- .../declarative_date_time.pl | 22 ++++++++++++++++++- reasoner.pl | 19 +--------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/declarative_date_time/declarative_date_time.pl b/declarative_date_time/declarative_date_time.pl index 755422a..688d740 100644 --- a/declarative_date_time/declarative_date_time.pl +++ b/declarative_date_time/declarative_date_time.pl @@ -1,7 +1,9 @@ :- module(declarative_date_time, [ valid_date/1, % valid_date_smt/1, to_date/2, - is_duration_before/3 + is_duration_before/3, + between_dates/3, + is_duration_before_after_within/4 ]). :- use_module(library(clpfd)). @@ -11,6 +13,24 @@ % :- py_add_lib_dir(declarative_date_time). % :- py_add_lib_dir(.). +is_duration_before_after_within(Date0, Duration, before, Date1) :- + is_duration_before(Date0, Duration, Date1). + +is_duration_before_after_within(Date0, Duration, after, Date1) :- + is_duration_before(Date1, Duration, Date0). + +is_duration_before_after_within(Date0, Duration, within, Date1) :- + is_duration_before(Date0, Duration, Date), + between_dates(Date0, Date1, Date), !. + +is_duration_before_after_within(Date0, Duration, within, Date1) :- + is_duration_before(Date, Duration, Date0), + between_dates(Date, Date1, Date0), !. + +between_dates(Date0, Date, Date1) :- + is_duration_before(Date0, days(_), Date), + is_duration_before(Date, days(_), Date1), !. + valid_year(Year) :- Year in 1900..2200. is_duration_before(Date, Duration, Date) :- diff --git a/reasoner.pl b/reasoner.pl index 742aa79..5bce5ed 100755 --- a/reasoner.pl +++ b/reasoner.pl @@ -18,7 +18,7 @@ run_examples/0, run_examples/1, myClause2/9, myClause/4, taxlogWrapper/10, niceModule/2, refToOrigin/2, isafter/2, is_not_before/2, isbefore/2, immediately_before/2, same_date/2, subtract_days/3, this_year/1, uk_tax_year/4, in/2, isExpressionFunctor/1, set_time_of_day/3, start_of_day/2, end_of_day/2, is_days_after/3, is_1_day_after/2, unparse_time/2, product_list/2, - valid_date/1, to_date/2, is_duration_before_after_within/4 + valid_date/1, to_date/2, between_dates/3, is_duration_before_after_within/4 % is_duration_before_dates/3 ]). @@ -726,23 +726,6 @@ format_time(string(Start),"%F",date(StartYear,4,6)), format_time(string(End),"%F",date(EndYear,4,5)). -is_duration_before_after_within(Date0, Duration, before, Date1) :- - is_duration_before(Date0, Duration, Date1). - -is_duration_before_after_within(Date0, Duration, after, Date1) :- - is_duration_before(Date1, Duration, Date0). - -is_duration_before_after_within(Date0, Duration, within, Date1) :- - is_duration_before(Date0, Duration, Date), - between_dates(Date0, Date1, Date). - -is_duration_before_after_within(Date0, Duration, within, Date1) :- - is_duration_before(Date, Duration, Date0), - between_dates(Date, Date1, Date0). - -between_dates(Date0, Date, Date1) :- - is_duration_before(Date0, _, Date), is_duration_before(Date, _, Date1). - %! in(X,List) is nondet. % X is in List in(X,List) :- must_be(list,List), member(X,List).