From cb65e6a0800ce16316eecf6da4239cadcc81a8fe Mon Sep 17 00:00:00 2001 From: linzhijun Date: Fri, 9 Aug 2024 18:17:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/toolgood/algorithm/internals/MathVisitor.java | 2 +- .../src/test/java/toolgood/algorithm/Tests/IssuesTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/MathVisitor.java b/java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/MathVisitor.java index 34eeb47..31285c6 100644 --- a/java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/MathVisitor.java +++ b/java/toolgood.algorithm/src/main/java/toolgood/algorithm/internals/MathVisitor.java @@ -2693,7 +2693,7 @@ public Operand visitDATEDIF_fun(final DATEDIF_funContext context) { return Operand.Create((endDate.Year * 12 + endDate.Month - startDate.Year * 12 - startDate.Month - 1)); } } else if (CharUtil.Equals(t, "d")) { - return Operand.Create(endDate.SUB(startDate).ToNumber().intValue()); + return Operand.Create((endDate.ToNumber().subtract(startDate.ToNumber())).intValue()); } else if (CharUtil.Equals(t, "yd")) { int day = endDate.DayOfYear() - startDate.DayOfYear(); if (endDate.Year > startDate.Year && day < 0) { diff --git a/java/toolgood.algorithm/src/test/java/toolgood/algorithm/Tests/IssuesTest.java b/java/toolgood.algorithm/src/test/java/toolgood/algorithm/Tests/IssuesTest.java index 499942d..48b9abf 100644 --- a/java/toolgood.algorithm/src/test/java/toolgood/algorithm/Tests/IssuesTest.java +++ b/java/toolgood.algorithm/src/test/java/toolgood/algorithm/Tests/IssuesTest.java @@ -36,6 +36,9 @@ public void issues_27() AlgorithmEngine engine = new AlgorithmEngine(); MyDate dt = engine.TryEvaluate("DATE(2024, 8, 1) + TIME(8, 0, 0)", MyDate.now()); assertEquals(dt.toString(), "2024-08-01 08:00:00"); + + MyDate dt2 = engine.TryEvaluate("DATE(2024, 8, 1, 16,0,0) - TIME(8, 0, 0)", MyDate.now()); + assertEquals(dt2.toString(), "2024-08-01 08:00:00"); } }