diff --git a/.gitignore b/.gitignore
index 6203922..c3b5ef4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,4 @@ packages
project.lock.json
.vs
/Math expression eval/UnitTest/UnitTest.csproj.user
+Math expression eval/ConsoleApp/Properties/PublishProfiles/FolderProfile.pubxml
diff --git a/Math expression eval/ConsoleApp/ConsoleApp.csproj b/Math expression eval/ConsoleApp/ConsoleApp.csproj
new file mode 100644
index 0000000..7ecd3b7
--- /dev/null
+++ b/Math expression eval/ConsoleApp/ConsoleApp.csproj
@@ -0,0 +1,14 @@
+
+
+
+ Exe
+ net7.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/Math expression eval/ConsoleApp/Program.cs b/Math expression eval/ConsoleApp/Program.cs
new file mode 100644
index 0000000..11ae821
--- /dev/null
+++ b/Math expression eval/ConsoleApp/Program.cs
@@ -0,0 +1,185 @@
+using org.matheval;
+
+
+Expression expression = new("minute(now())");
+var val = expression.Eval();
+Console.WriteLine(val);
+
+
+//Console.WriteLine("datevalue test");
+//expression = new("datevalue('2023-01-15')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("datevalue('2023/01/15')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("datevalue('12-25-2022')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("datevalue('12/25/2022')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("Time test");
+//expression = new("time(10,15,32)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("time(23,59,59)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("time(1111,59,59)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("second test");
+//expression = new("second('01:23:20')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("second('03/30/2022 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+////expression = new("second('03/30/2022')");
+////val = expression.Eval();
+////Console.WriteLine(val);
+
+
+//Console.WriteLine("minute test");
+//expression = new("minute('01:23:20')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("minute('03/30/2022 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+////expression = new("minute('03/30/2022')");
+////val = expression.Eval();
+////Console.WriteLine(val);
+
+//Console.WriteLine("hour test");
+//expression = new("hour('01:23:20')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("hour('03/30/2022 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("day test");
+//expression = new("day('03/15/2022')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("day('05/30/2022 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+
+//Console.WriteLine("month test");
+//expression = new("month('03/15/2022')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("month('05/30/2022 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("now test");
+//expression = new("now()");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("edate test");
+//expression = new("edate('05/30/2022 04:50:45',5)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("edate('05/30/2022',20)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+
+//Console.WriteLine("weekday test");
+//DateTime date = new DateTime();
+//for (int i = 0; i < 8; i++)
+//{
+// date = DateTime.UtcNow.AddDays(i);
+// expression = new("weekday('" + date.ToString() + "')");
+// val = expression.Eval();
+// Console.WriteLine(date.DayOfWeek + ": " + val.ToString());
+//}
+
+//Console.WriteLine("weeknum test");
+//expression = new("weeknum('01/01/2022 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("weeknum('12/20/2022')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("workday test");
+//expression = new("workday('01/01/2023 04:50:45',3)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("workday('01/01/2023 04:50:45',-3)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("workday('01/01/2023',20)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("workday('01/01/2023',99)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("networkday test");
+//expression = new("networkdays('01/01/2023 04:50:45','01/25/2023 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("networkdays('01/01/2023 04:50:45','02/25/2023 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("networkdays('01/01/2023 04:50:45','01/01/2023 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("eomonth test");
+//expression = new("eomonth('01/01/2023 04:50:45',2)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("eomonth('01/01/2023',2)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("eomonth('01/01/2023 04:50:45',11)");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("datedif test");
+//expression = new("datedif('01/01/2023 04:50:45','02/05/2023 04:50:45','day')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("datedif('01/01/2023','01/01/2024','day')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("datedif('01/01/2023','04/08/2023','day')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//expression = new("datedif('01/01/2023','03/03/2023','month')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("datedif('01/01/2023','04/25/2024','month')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//expression = new("datedif('01/01/2023','07/01/2023','year')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("datedif('01/01/2023','04/25/2025','year')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+
+//Console.WriteLine("days test");
+//expression = new("days('01/01/2023 04:50:45','01/05/2023 04:50:45')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("days('01/01/2023','01/01/2024')");
+//val = expression.Eval();
+//Console.WriteLine(val);
+//expression = new("days('01/01/2023','04/08/2023')");
+//val = expression.Eval();
+//Console.WriteLine(val);
diff --git a/Math expression eval/Math expression eval.sln b/Math expression eval/Math expression eval.sln
index 0236dfe..58f58b8 100644
--- a/Math expression eval/Math expression eval.sln
+++ b/Math expression eval/Math expression eval.sln
@@ -1,12 +1,14 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.30907.101
+# Visual Studio Version 17
+VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "org.matheval", "org.matheval\org.matheval.csproj", "{85774930-C0E9-432C-A23F-015FB26F3897}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "UnitTest\UnitTest.csproj", "{3FFECB40-1C8E-4362-9476-BEBB4EE329BD}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{E88BE99B-5A05-49F3-97D0-AC12D5A5F5A7}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
{3FFECB40-1C8E-4362-9476-BEBB4EE329BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FFECB40-1C8E-4362-9476-BEBB4EE329BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FFECB40-1C8E-4362-9476-BEBB4EE329BD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E88BE99B-5A05-49F3-97D0-AC12D5A5F5A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E88BE99B-5A05-49F3-97D0-AC12D5A5F5A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E88BE99B-5A05-49F3-97D0-AC12D5A5F5A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E88BE99B-5A05-49F3-97D0-AC12D5A5F5A7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Math expression eval/UnitTest/Afe_CommonTests.cs b/Math expression eval/UnitTest/Afe_CommonTests.cs
new file mode 100644
index 0000000..6ca18ab
--- /dev/null
+++ b/Math expression eval/UnitTest/Afe_CommonTests.cs
@@ -0,0 +1,73 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using org.matheval.Common;
+using System;
+using System.Globalization;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class Afe_CommonTests
+ {
+ [TestMethod]
+ public void ReturnsDateTime()
+ {
+ CultureInfo dc = new CultureInfo("en-US");
+ var dateTimeString = "2023-01-01";
+ Assert.IsInstanceOfType(Afe_Common.ToDateTime(dateTimeString, dc), typeof(DateTime));
+
+ dateTimeString = "2023-01-01 12:12:12";
+ Assert.IsInstanceOfType(Afe_Common.ToDateTime(dateTimeString, dc), typeof(DateTime));
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(ArgumentException))]
+ public void ToDateTimeArgumentException()
+ {
+ CultureInfo dc = new CultureInfo("en-US");
+ Afe_Common.ToDateTime("12:12:12", dc);
+ }
+
+ [TestMethod]
+ public void TimeValidationReturnsDateTime()
+ {
+ DateTime dateTime= DateTime.Parse("2023-01-01 12:12:12");
+ Assert.AreEqual(Afe_Common.TimeValidation(dateTime), dateTime);
+
+ dateTime = DateTime.Parse("12:12:12");
+ Assert.AreEqual(Afe_Common.TimeValidation(dateTime), dateTime);
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(ArgumentException))]
+ public void TimeValidationTimeArgumentException()
+ {
+ DateTime dateTime = DateTime.Parse("2023-01-01");
+ Afe_Common.TimeValidation(dateTime);
+ }
+ }
+}
+
diff --git a/Math expression eval/UnitTest/DateDifFunctionTest.cs b/Math expression eval/UnitTest/DateDifFunctionTest.cs
new file mode 100644
index 0000000..48fcee2
--- /dev/null
+++ b/Math expression eval/UnitTest/DateDifFunctionTest.cs
@@ -0,0 +1,67 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using System;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class DateDifFunctionTest
+ {
+ [TestMethod]
+ public void DayDifference()
+ {
+ Expression expression = new Expression("datedif('01/01/2023 04:50:45','02/05/2023 04:50:45','day')");
+ Assert.AreEqual((decimal)35, expression.Eval());
+
+ expression = new Expression("datedif('01/01/2023','01/01/2024','day')");
+ Assert.AreEqual((decimal)365, expression.Eval());
+
+ expression = new Expression("datedif('01/01/2023','04/11/2023','day')");
+ Assert.AreEqual((decimal)100, expression.Eval());
+ }
+
+ [TestMethod]
+ public void MonthDifference()
+ {
+ Expression expression = new Expression("datedif('01/01/2023','03/03/2023','month')");
+ Assert.AreEqual((decimal)2, expression.Eval());
+
+ expression = new Expression("datedif('01/01/2023','04/25/2024','month')");
+ Assert.AreEqual((decimal)15, expression.Eval());
+ }
+
+ [TestMethod]
+ public void YearDifference()
+ {
+ Expression expression = new Expression("datedif('01/01/2023','07/01/2023','year')");
+ Assert.AreEqual((decimal).50, expression.Eval());
+
+ expression = new Expression("datedif('01/01/2023','04/25/2025','year')");
+ Assert.AreEqual((decimal)2.25, expression.Eval());
+ }
+ }
+}
+
diff --git a/Math expression eval/UnitTest/MinuteFunctionTest.cs b/Math expression eval/UnitTest/MinuteFunctionTest.cs
new file mode 100644
index 0000000..f546fc3
--- /dev/null
+++ b/Math expression eval/UnitTest/MinuteFunctionTest.cs
@@ -0,0 +1,43 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using System;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class MinuteFunctionTest
+ {
+ [TestMethod]
+ public void ReturnMinutes()
+ {
+ Expression expression = new Expression("minute('01:23:20')"); ;
+ Assert.AreEqual(23, expression.Eval());
+
+ expression = new Expression("minute('03/30/2022 04:50:45')");
+ Assert.AreEqual(50, expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/MonthFunctionTest.cs b/Math expression eval/UnitTest/MonthFunctionTest.cs
new file mode 100644
index 0000000..8e351b7
--- /dev/null
+++ b/Math expression eval/UnitTest/MonthFunctionTest.cs
@@ -0,0 +1,43 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using System;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class MonthFunctionTest
+ {
+ [TestMethod]
+ public void ReturnMonths()
+ {
+ Expression expression = new Expression("month('03/15/2022')");
+ Assert.AreEqual(03, expression.Eval());
+
+ expression = new Expression("month('05/30/2022 04:50:45')");
+ Assert.AreEqual(05, expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/TodayFunctionTest.cs b/Math expression eval/UnitTest/TodayFunctionTest.cs
new file mode 100644
index 0000000..0ecf81d
--- /dev/null
+++ b/Math expression eval/UnitTest/TodayFunctionTest.cs
@@ -0,0 +1,40 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using System;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class TodayFunctionTest
+ {
+ [TestMethod]
+ public void ReturnCurrentDate()
+ {
+ Expression expression = new Expression("Today()");
+ Assert.AreEqual(DateTime.Today.Date, DateTime.Parse(expression.Eval().ToString()).Date);
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/UnitTest.csproj b/Math expression eval/UnitTest/UnitTest.csproj
index b9dc132..1cefac0 100644
--- a/Math expression eval/UnitTest/UnitTest.csproj
+++ b/Math expression eval/UnitTest/UnitTest.csproj
@@ -1,7 +1,7 @@
- netcoreapp2.1;
+ netcoreapp2.1;net7.0
false
diff --git a/Math expression eval/UnitTest/dateFunctionTest.cs b/Math expression eval/UnitTest/dateFunctionTest.cs
new file mode 100644
index 0000000..b2e1ee8
--- /dev/null
+++ b/Math expression eval/UnitTest/dateFunctionTest.cs
@@ -0,0 +1,39 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class DateFunctionTest
+ {
+ [TestMethod]
+ public void CreateDate()
+ {
+ Expression expr1 = new Expression("date(2022, 3, 30)");
+ Assert.AreEqual("03/30/2022 00:00:00", expr1.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/datevalueFunctionTest.cs b/Math expression eval/UnitTest/datevalueFunctionTest.cs
new file mode 100644
index 0000000..cf00631
--- /dev/null
+++ b/Math expression eval/UnitTest/datevalueFunctionTest.cs
@@ -0,0 +1,42 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class DateValueFunctionTest
+ {
+ [TestMethod]
+ public void CreateDateFromString()
+ {
+ Expression epression = new Expression("datevalue('2023-01-01')");
+ Assert.AreEqual("01/01/2023 00:00:00", epression.Eval());
+
+ epression = new Expression("datevalue('2023/09/22')");
+ Assert.AreEqual("09/22/2023 00:00:00", epression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/dayFunctionTest.cs b/Math expression eval/UnitTest/dayFunctionTest.cs
new file mode 100644
index 0000000..ded3f12
--- /dev/null
+++ b/Math expression eval/UnitTest/dayFunctionTest.cs
@@ -0,0 +1,43 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using System;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class DayFunctionTest
+ {
+ [TestMethod]
+ public void ReturnDays()
+ {
+ Expression expression = new Expression("day('03/15/2022')");
+ Assert.AreEqual(15, expression.Eval());
+
+ expression = new Expression("day('05/30/2022 04:50:45')");
+ Assert.AreEqual(30, expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/daysFunctionTest.cs b/Math expression eval/UnitTest/daysFunctionTest.cs
new file mode 100644
index 0000000..9879035
--- /dev/null
+++ b/Math expression eval/UnitTest/daysFunctionTest.cs
@@ -0,0 +1,42 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class DaysFunctionTest
+ {
+ [TestMethod]
+ public void DaysBetweenDates()
+ {
+ Expression expression = new Expression("days('01/01/2023 04:50:45','01/05/2023 04:50:45')");
+ Assert.AreEqual(4, expression.Eval());
+
+ expression = new Expression("days('01/01/2023','01/01/2024')");
+ Assert.AreEqual(365, expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/edateFunctionTest.cs b/Math expression eval/UnitTest/edateFunctionTest.cs
new file mode 100644
index 0000000..e7c96f4
--- /dev/null
+++ b/Math expression eval/UnitTest/edateFunctionTest.cs
@@ -0,0 +1,54 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using System;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class EDateFunctionTest
+ {
+ [TestMethod]
+ public void AddMonthsToDate()
+ {
+ Expression expression = new Expression("edate('05/30/2022 04:50:45',5)");
+ Assert.AreEqual("10/30/2022 04:50:45", expression.Eval());
+
+ expression = new Expression("edate('05/30/2022',15)");
+ Assert.AreEqual("08/30/2023 00:00:00", expression.Eval());
+ }
+
+ [TestMethod]
+ public void SubtractMonthsFromDate()
+ {
+ Expression expression = new Expression("edate('05/30/2022 04:50:45',-5)");
+ Assert.AreEqual("12/30/2021 04:50:45", expression.Eval());
+
+ expression = new Expression("edate('05/30/2022',-1)");
+ Assert.AreEqual("04/30/2022 00:00:00", expression.Eval());
+ }
+ }
+}
+
diff --git a/Math expression eval/UnitTest/eomonthFunctionTest.cs b/Math expression eval/UnitTest/eomonthFunctionTest.cs
new file mode 100644
index 0000000..4b2d1da
--- /dev/null
+++ b/Math expression eval/UnitTest/eomonthFunctionTest.cs
@@ -0,0 +1,42 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class EMonthFunctionTest
+ {
+ [TestMethod]
+ public void EndOfMonth()
+ {
+ Expression expression = new Expression("eomonth('01/01/2023',2)");
+ Assert.AreEqual("03/31/2023 00:00:00", expression.Eval());
+
+ expression = new Expression("eomonth('01/01/2023',12)");
+ Assert.AreEqual("01/31/2024 00:00:00", expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/hourFunctionTest.cs b/Math expression eval/UnitTest/hourFunctionTest.cs
new file mode 100644
index 0000000..5ed13d6
--- /dev/null
+++ b/Math expression eval/UnitTest/hourFunctionTest.cs
@@ -0,0 +1,41 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class HourFunctionTest
+ {
+ [TestMethod]
+ public void ReturnHours()
+ {
+ Expression expression = new Expression("hour('01:23:20')");
+ Assert.AreEqual(01, expression.Eval());
+ expression = new Expression("hour('03/30/2022 04:50:45')");
+ Assert.AreEqual(04, expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/networkdayFunctionTest.cs b/Math expression eval/UnitTest/networkdayFunctionTest.cs
new file mode 100644
index 0000000..2740692
--- /dev/null
+++ b/Math expression eval/UnitTest/networkdayFunctionTest.cs
@@ -0,0 +1,42 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class NetWorkDayFunctionTest
+ {
+ [TestMethod]
+ public void CalculateWorkDaysBetweenDates()
+ {
+ Expression expression = new Expression("networkdays('01/01/2023 04:50:45','01/22/2023 04:50:45')");
+ Assert.AreEqual(15, expression.Eval());
+
+ expression = new Expression("networkdays('01/01/2023 04:50:45','01/01/2023 04:50:45')");
+ Assert.AreEqual(0, expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/nowFunctionTest.cs b/Math expression eval/UnitTest/nowFunctionTest.cs
new file mode 100644
index 0000000..225bac3
--- /dev/null
+++ b/Math expression eval/UnitTest/nowFunctionTest.cs
@@ -0,0 +1,40 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using System;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class NowFunctionTest
+ {
+ [TestMethod]
+ public void ReturnCurrentDate()
+ {
+ Expression expression = new Expression("now()");
+ Assert.AreEqual(DateTime.UtcNow.Date, DateTime.Parse(expression.Eval().ToString()).Date);
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/secondFunctionTest.cs b/Math expression eval/UnitTest/secondFunctionTest.cs
new file mode 100644
index 0000000..34a0f4e
--- /dev/null
+++ b/Math expression eval/UnitTest/secondFunctionTest.cs
@@ -0,0 +1,43 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class SecondFunctionTest
+ {
+ [TestMethod]
+ public void ReturnSeconds()
+ {
+ Expression expression = new Expression("second('01:23:20')");
+ Assert.AreEqual(20, expression.Eval());
+
+ expression = new Expression("second('03/30/2022 04:05:45')");
+ Assert.AreEqual(45, expression.Eval());
+
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/timeFunctionTest.cs b/Math expression eval/UnitTest/timeFunctionTest.cs
new file mode 100644
index 0000000..9d72436
--- /dev/null
+++ b/Math expression eval/UnitTest/timeFunctionTest.cs
@@ -0,0 +1,39 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class TimeFunctionTest
+ {
+ [TestMethod]
+ public void ReturnTime()
+ {
+ Expression expression = new Expression("time(10,15,32)");
+ Assert.AreEqual("10:15:32", expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/weekdayFunctionTest.cs b/Math expression eval/UnitTest/weekdayFunctionTest.cs
new file mode 100644
index 0000000..0fc1e86
--- /dev/null
+++ b/Math expression eval/UnitTest/weekdayFunctionTest.cs
@@ -0,0 +1,46 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using System;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class WeekDayFunctionTest
+ {
+ [TestMethod]
+ public void ReturnDayOfWeekNumber()
+ {
+ DateTime date = new DateTime(2023,01,01);//sunday
+ Expression expression = new Expression();
+ for (int i = 1; i <= 7; i++)
+ {
+ expression = new Expression("weekday('" + date.ToString() + "')");
+ Assert.AreEqual(i, expression.Eval());
+ date = date.AddDays(1);
+ }
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/weeknumberFunctionTest.cs b/Math expression eval/UnitTest/weeknumberFunctionTest.cs
new file mode 100644
index 0000000..7b5ca1b
--- /dev/null
+++ b/Math expression eval/UnitTest/weeknumberFunctionTest.cs
@@ -0,0 +1,43 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+using System;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class WeekNumberFunctionTest
+ {
+ [TestMethod]
+ public void CalculatesWeekNumber()
+ {
+ Expression expression = new Expression("weeknum('01/01/2022 04:50:45')");
+ Assert.AreEqual(1, expression.Eval());
+
+ expression = new Expression("weeknum('12/20/2022 04:50:45')");
+ Assert.AreEqual(52, expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/workdayFunctionTest.cs b/Math expression eval/UnitTest/workdayFunctionTest.cs
new file mode 100644
index 0000000..5e78682
--- /dev/null
+++ b/Math expression eval/UnitTest/workdayFunctionTest.cs
@@ -0,0 +1,51 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class WorkDayFunctionTest
+ {
+ [TestMethod]
+ public void ReturnDatePositiveWorkDay()
+ {
+ Expression expression = new Expression("workday('01/01/2023 04:50:45',3)");
+ Assert.AreEqual("01/05/2023 04:50:45", expression.Eval());
+
+ expression = new Expression("workday('01/01/2023',7)");
+ Assert.AreEqual("01/11/2023 00:00:00", expression.Eval());
+ }
+ [TestMethod]
+ public void ReturnDateNegativeWorkDay()
+ {
+ Expression expression = new Expression("workday('01/01/2023 04:50:45',-3)");
+ Assert.AreEqual("12/27/2022 04:50:45", expression.Eval());
+
+ expression = new Expression("workday('01/01/2023',-7)");
+ Assert.AreEqual("12/21/2022 00:00:00", expression.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/UnitTest/yearFunctionTest.cs b/Math expression eval/UnitTest/yearFunctionTest.cs
new file mode 100644
index 0000000..1eb2021
--- /dev/null
+++ b/Math expression eval/UnitTest/yearFunctionTest.cs
@@ -0,0 +1,39 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using org.matheval;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class YearFunctionTest
+ {
+ [TestMethod]
+ public void ReturnYear()
+ {
+ Expression expr1 = new Expression("year('05/30/2022 04:50:45')");
+ Assert.AreEqual(2022, expr1.Eval());
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Common/Afe_Common.cs b/Math expression eval/org.matheval/Common/Afe_Common.cs
index dd4c207..4cece79 100644
--- a/Math expression eval/org.matheval/Common/Afe_Common.cs
+++ b/Math expression eval/org.matheval/Common/Afe_Common.cs
@@ -231,28 +231,18 @@ public static class Afe_Common
///
/// Funtion TODAY
///
- public const string Const_TODAY = "TODAY";
+ public const string Const_TODAY = "today";
///
/// Funtion left
///
public const string Const_LEFT = "left";
- ///
- /// Function Second
- ///
- public const string Const_Second = "second";
-
///
/// Function code
///
public const string Const_Code = "code";
- ///
- /// Function hour
- ///
- public const string Const_Hour = "hour";
-
///
/// Function int
///
@@ -263,12 +253,6 @@ public static class Afe_Common
///
public const string Const_Isblank = "isblank";
- ///
- /// Function Minute
- ///
- public const string Const_Minute = "minute";
-
-
///
/// Function proper
///
@@ -585,12 +569,6 @@ public static class Afe_Common
///
public const string Const_Round = "round";
-
- ///
- /// Function time
- ///
- public const string Const_Time = "time";
-
///
/// Function Exp
///
@@ -606,6 +584,81 @@ public static class Afe_Common
///
public const string Const_Find = "find";
+ ///
+ /// Function Date
+ ///
+ public const string Const_Date = "date";
+ ///
+ /// Function DateValue
+ ///
+ public const string Const_DateValue = "datevalue";
+ ///
+ /// Function Time
+ ///
+ public const string Const_Time = "time";
+ ///
+ /// Function Time
+ ///
+ public const string Const_Second = "second";
+ ///
+ /// Function Time
+ ///
+ public const string Const_Minute = "minute";
+ ///
+ /// Function Time
+ ///
+ public const string Const_Hour = "hour";
+ ///
+ /// Function Time
+ ///
+ public const string Const_Day = "day";
+ ///
+ /// Function Time
+ ///
+ public const string Const_Month = "month";
+
+ ///
+ /// Function Year
+ ///
+ public const string Const_Year = "year";
+
+ ///
+ /// Function Year
+ ///
+ public const string Const_Now = "now";
+
+ ///
+ /// Function Today
+ ///
+ public const string Const_EDate = "edate";
+ ///
+ /// Function Today
+ ///
+ public const string Const_Weekday = "weekday";
+ ///
+ /// Function Today
+ ///
+ public const string Const_WeekNum = "weeknum";
+ ///
+ /// Function Today
+ ///
+ public const string Const_Workday = "workday";
+ ///
+ /// Function Today
+ ///
+ public const string Const_NetWorkdays = "networkdays";
+ ///
+ /// Function Today
+ ///
+ public const string Const_EOMonth = "eomonth";
+ ///
+ /// Function Today
+ ///
+ public const string Const_DateDif = "datedif";
+ ///
+ /// Function Today
+ ///
+ public const string Const_Days = "days";
#endregion
@@ -765,12 +818,53 @@ public static decimal ToDecimal(object value, CultureInfo cultureInfo)
}
///
- /// Connvert object to string
/// TODO poner default invariant culture.
///
///
///
///
+ public static int ToInteger(object value, CultureInfo cultureInfo)
+ {
+ if (value is int)
+ {
+ return (int)value;
+ }
+ else
+ {
+ return Convert.ToInt32(value, cultureInfo);
+ }
+ }
+
+ ///
+ /// connvert object to string
+ /// todo poner default invariant culture.
+ ///
+ ///
+ ///
+ ///
+ public static DateTime ToDateTime(object value, CultureInfo cultureInfo)
+ {
+ if(value is DateTime)
+ {
+ return (DateTime)value;
+ }
+ else if (TimeSpan.TryParse(value.ToString(), out _))
+ {
+ throw new ArgumentException("Date is Invalid");
+ }
+ else
+ {
+ return Convert.ToDateTime(value, cultureInfo);
+ }
+ }
+
+ ///
+ /// connvert object to string
+ /// todo poner default invariant culture.
+ ///
+ ///
+ ///
+ ///
public static string ToString(object value, CultureInfo cultureInfo)
{
if (value is string)
@@ -783,8 +877,6 @@ public static string ToString(object value, CultureInfo cultureInfo)
}
}
-
-
///
/// Check object instance of List
///
@@ -865,6 +957,20 @@ public static int DateDif(DateTime startDate, DateTime endDate, string unit)
throw new Exception("Please set M or D or Y for UNIT param");
}
+ ///
+ /// DateDif
+ ///
+ /// dateTime
+ /// Blank Time Check
+ ///
+ public static DateTime TimeValidation (DateTime dateTime)
+ {
+ if (dateTime.ToString("HH:mm:ss") == "00:00:00")
+ {
+ throw new ArgumentException("Time is Invalid");
+ }
+ return dateTime;
+ }
#endregion
#region Enum
diff --git a/Math expression eval/org.matheval/Functions/Impl/SecondFunction.cs b/Math expression eval/org.matheval/Functions/Impl/SecondFunction.cs
new file mode 100644
index 0000000..07adbd5
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/SecondFunction.cs
@@ -0,0 +1,58 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the second component of a Time, Datetime
+ ///
+ public class secondFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_Second, new System.Type[]{typeof(string)}, typeof(decimal), 1)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = DateTime.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture));
+ return Afe_Common.ToInteger(Afe_Common.TimeValidation(dateTime).Second, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/dateFunction.cs b/Math expression eval/org.matheval/Functions/Impl/dateFunction.cs
new file mode 100644
index 0000000..a687b8e
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/dateFunction.cs
@@ -0,0 +1,61 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Constructs a Date from Integer representations of the year, month (1=Jan), and day
+ ///
+ public class dateFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List
+ {
+ new FunctionDef(Afe_Common.Const_Date, new Type[] { typeof(decimal), typeof(decimal), typeof(decimal) }, typeof(string), 3)
+ };
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var year = Afe_Common.ToInteger(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ var month = Afe_Common.ToInteger(args[Afe_Common.Const_Key_Two], dc.WorkingCulture);
+ var day = Afe_Common.ToInteger(args[Afe_Common.Const_Key_Three], dc.WorkingCulture);
+ return Afe_Common.ToString(new DateTime(year, month, day), dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/datedifFunction.cs b/Math expression eval/org.matheval/Functions/Impl/datedifFunction.cs
new file mode 100644
index 0000000..640480f
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/datedifFunction.cs
@@ -0,0 +1,75 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Calculates the number of days, months, or years between two dates.
+ ///
+ public class datedifFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_DateDif, new System.Type[]{typeof(string), typeof(string), typeof(string)}, typeof(decimal), 3)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var startDate = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ var endDate = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_Two], dc.WorkingCulture);
+ var unit = Afe_Common.ToString(args[Afe_Common.Const_Key_Three], dc.WorkingCulture);
+ return Afe_Common.ToDecimal(SubtractDates(startDate, endDate, unit), dc.WorkingCulture);
+ }
+
+ private static string SubtractDates(DateTime startDate, DateTime endDate, string unit)
+ {
+ switch (unit)
+ {
+ case "day":
+ return endDate.Subtract(startDate).TotalDays.ToString();
+ case "month":
+ return (((endDate.Year - startDate.Year) * 12) + endDate.Month - startDate.Month).ToString();
+ case "year":
+ return ((decimal)(((endDate.Year - startDate.Year) * 12) + endDate.Month - startDate.Month) / 12).ToString(".##");
+ default:
+ return null;
+ }
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/datevalueFunction.cs b/Math expression eval/org.matheval/Functions/Impl/datevalueFunction.cs
new file mode 100644
index 0000000..c93ccf8
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/datevalueFunction.cs
@@ -0,0 +1,61 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Constructs a Date from String representations of the year–month–day
+ ///
+ public class datevalueFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List
+ {
+ new FunctionDef(Afe_Common.Const_DateValue, new Type[] { typeof(string) }, typeof(string), 1)
+ };
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ return Afe_Common.ToString(dateTime, dc.WorkingCulture);
+
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/dayFunction.cs b/Math expression eval/org.matheval/Functions/Impl/dayFunction.cs
new file mode 100644
index 0000000..c248cac
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/dayFunction.cs
@@ -0,0 +1,58 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the day component of a Date, Datetime
+ ///
+ public class dayFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_Day, new System.Type[]{typeof(string)}, typeof(decimal), 1)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ return Afe_Common.ToInteger(dateTime.Day, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/daysFunction.cs b/Math expression eval/org.matheval/Functions/Impl/daysFunction.cs
new file mode 100644
index 0000000..fba547e
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/daysFunction.cs
@@ -0,0 +1,59 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the number of days between two dates
+ ///
+ public class daysFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_Days, new System.Type[]{typeof(string), typeof(string)}, typeof(decimal), 2)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var startDate = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ var endDate = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_Two], dc.WorkingCulture);
+ return Afe_Common.ToInteger(endDate.Subtract(startDate).TotalDays, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/edateFunction.cs b/Math expression eval/org.matheval/Functions/Impl/edateFunction.cs
new file mode 100644
index 0000000..b0074a6
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/edateFunction.cs
@@ -0,0 +1,60 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Add month to Date, Datime
+ ///
+ public class edateFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List
+ {
+ new FunctionDef(Afe_Common.Const_EDate, new Type[] { typeof(string), typeof(decimal) }, typeof(string), 2)
+ };
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ var month = Afe_Common.ToInteger(args[Afe_Common.Const_Key_Two], dc.WorkingCulture);
+ return Afe_Common.ToString(dateTime.AddMonths(month), dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/eomonthFunction.cs b/Math expression eval/org.matheval/Functions/Impl/eomonthFunction.cs
new file mode 100644
index 0000000..cb7ac52
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/eomonthFunction.cs
@@ -0,0 +1,58 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ // Calculates the last day of the month after adding a specified number of months to a date, datetime
+ ///
+ public class eomonthFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List { new FunctionDef(Afe_Common.Const_EOMonth, new System.Type[] { typeof(string), typeof(decimal) }, typeof(string), 2) };
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ var months = Afe_Common.ToInteger(args[Afe_Common.Const_Key_Two], dc.WorkingCulture);
+ var dateMonths = dateTime.AddMonths(months);
+ return Afe_Common.ToString(new DateTime(dateMonths.Year, dateMonths.Month, DateTime.DaysInMonth(dateMonths.Year, dateMonths.Month)), dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/hourFunction.cs b/Math expression eval/org.matheval/Functions/Impl/hourFunction.cs
new file mode 100644
index 0000000..2299aa9
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/hourFunction.cs
@@ -0,0 +1,58 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the hour component of a Time, Datetime
+ ///
+ public class hourFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_Hour, new System.Type[]{typeof(string)}, typeof(decimal), 1)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = Afe_Common.TimeValidation(DateTime.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture)));
+ return Afe_Common.ToInteger(dateTime.Hour, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/minuteFunction.cs b/Math expression eval/org.matheval/Functions/Impl/minuteFunction.cs
new file mode 100644
index 0000000..6eb663c
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/minuteFunction.cs
@@ -0,0 +1,58 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the minute component of a Time, Datetime
+ ///
+ public class minuteFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_Minute, new System.Type[]{typeof(string)}, typeof(decimal), 1)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = DateTime.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture));
+ return Afe_Common.ToInteger(Afe_Common.TimeValidation(dateTime).Minute, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/monthFunction.cs b/Math expression eval/org.matheval/Functions/Impl/monthFunction.cs
new file mode 100644
index 0000000..7cc4a55
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/monthFunction.cs
@@ -0,0 +1,58 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the month component of a Date, Datetime
+ ///
+ public class monthFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_Month, new System.Type[]{typeof(string)}, typeof(decimal), 1)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = DateTime.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture));
+ return Afe_Common.ToInteger(dateTime.Month, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/networkdaysFunction.cs b/Math expression eval/org.matheval/Functions/Impl/networkdaysFunction.cs
new file mode 100644
index 0000000..c05be44
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/networkdaysFunction.cs
@@ -0,0 +1,86 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the number of whole workdays between two dates
+ ///
+ public class networkdaysFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_NetWorkdays, new System.Type[]{typeof(string),typeof(string) }, typeof(decimal), 2)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var startDate = DateTime.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture));
+ var endDate = DateTime.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_Two], dc.WorkingCulture));
+ TimeSpan span = endDate - startDate;
+
+ //adjusted from https://stackoverflow.com/questions/1617049/calculate-the-number-of-business-days-between-two-dates
+ int businessDays = span.Days + 1;
+ int fullWeekCount = businessDays / 7;
+ // find out if there are weekends
+ if (businessDays > fullWeekCount * 7)
+ {
+ int firstDayOfWeek = startDate.DayOfWeek == DayOfWeek.Sunday
+ ? 7 : (int)startDate.DayOfWeek;
+ int lastDayOfWeek = endDate.DayOfWeek == DayOfWeek.Sunday
+ ? 7 : (int)endDate.DayOfWeek;
+ if (lastDayOfWeek < firstDayOfWeek)
+ lastDayOfWeek += 7;
+ if (firstDayOfWeek <= 6)
+ {
+ if (lastDayOfWeek >= 7)
+ businessDays -= 2;
+ else if (lastDayOfWeek >= 6)
+ businessDays -= 1;
+ }
+ else if (firstDayOfWeek <= 7 && lastDayOfWeek >= 7)
+ businessDays -= 1;
+ }
+ //subtract the weekends during the full weeks in the interval
+ businessDays -= fullWeekCount + fullWeekCount;
+ return Afe_Common.ToInteger(businessDays, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/nowFunction.cs b/Math expression eval/org.matheval/Functions/Impl/nowFunction.cs
new file mode 100644
index 0000000..6b1c11c
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/nowFunction.cs
@@ -0,0 +1,55 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the current Datetime based on a GMT calendar
+ ///
+ public class nowFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List { new FunctionDef(Afe_Common.Const_Now, null, typeof(string), 0) };
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ return DateTime.UtcNow.ToString();
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/timeFunction.cs b/Math expression eval/org.matheval/Functions/Impl/timeFunction.cs
new file mode 100644
index 0000000..d649713
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/timeFunction.cs
@@ -0,0 +1,60 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Constructs a Time instance from Integer representations of the hour, minute, and second
+ ///
+ public class timeFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_Time, new System.Type[]{typeof(decimal), typeof(decimal), typeof(decimal)}, typeof(string), 3)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var hours = Afe_Common.ToInteger(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ var minutes = Afe_Common.ToInteger(args[Afe_Common.Const_Key_Two], dc.WorkingCulture);
+ var seconds = Afe_Common.ToInteger(args[Afe_Common.Const_Key_Three], dc.WorkingCulture);
+ return Afe_Common.ToString(new TimeSpan(hours, minutes, seconds), dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/weekdayFunction .cs b/Math expression eval/org.matheval/Functions/Impl/weekdayFunction .cs
new file mode 100644
index 0000000..b1652f8
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/weekdayFunction .cs
@@ -0,0 +1,83 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the day of the week corresponding to a date. The day is given as an integer, ranging from 1 (Sunday) to 7 (Saturday)
+ ///
+ public class weekdayFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_Weekday, new System.Type[]{typeof(string)}, typeof(decimal), 1)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ int day = 0;
+ switch (dateTime.DayOfWeek.ToString())
+ {
+ case "Sunday":
+ day = 1;
+ break;
+ case "Monday":
+ day = 2;
+ break;
+ case "Tuesday":
+ day = 3;
+ break;
+ case "Wednesday":
+ day = 4;
+ break;
+ case "Thursday":
+ day = 5;
+ break;
+ case "Friday":
+ day = 6;
+ break;
+ case "Saturday":
+ day = 7;
+ break;
+ }
+ return Afe_Common.ToInteger(day, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/weeknumFunction.cs b/Math expression eval/org.matheval/Functions/Impl/weeknumFunction.cs
new file mode 100644
index 0000000..69b8a02
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/weeknumFunction.cs
@@ -0,0 +1,60 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the day of the week corresponding to a date. The day is given as an integer, ranging from 1 (Sunday) to 7 (Saturday)
+ ///
+ public class weeknumFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_WeekNum, new System.Type[]{typeof(string)}, typeof(decimal), 1)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ var weekNum = dc.WorkingCulture.Calendar.GetWeekOfYear(dateTime, dc.WorkingCulture.DateTimeFormat.CalendarWeekRule, dc.WorkingCulture.DateTimeFormat.FirstDayOfWeek);
+ return Afe_Common.ToInteger(weekNum, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/workdayFunction.cs b/Math expression eval/org.matheval/Functions/Impl/workdayFunction.cs
new file mode 100644
index 0000000..a174c59
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/workdayFunction.cs
@@ -0,0 +1,70 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns a number that represents a date that is the indicated number of working days before or after a date (the starting date).
+ ///
+ public class workdayFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List{
+ new FunctionDef(Afe_Common.Const_Workday, new System.Type[]{typeof(string),typeof(decimal)}, typeof(string), 2)};
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var date = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One], dc.WorkingCulture);
+ var days = Afe_Common.ToInteger(args[Afe_Common.Const_Key_Two], dc.WorkingCulture);
+ int i = 0;
+ while (i < Math.Abs(days))
+ {
+ var dayOfWeek = date.DayOfWeek.ToString();
+ if (dayOfWeek != "Saturday" && dayOfWeek != "Sunday")
+ {
+ i++;
+ }
+ date = days >= 0 ? date.AddDays(1) : date.AddDays(-1);
+ }
+ return Afe_Common.ToString(date, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/Functions/Impl/yearFunction.cs b/Math expression eval/org.matheval/Functions/Impl/yearFunction.cs
new file mode 100644
index 0000000..1af8187
--- /dev/null
+++ b/Math expression eval/org.matheval/Functions/Impl/yearFunction.cs
@@ -0,0 +1,59 @@
+/*
+ The MIT License
+
+ Copyright (c) 2021 MathEval.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+using org.matheval.Common;
+using System;
+using System.Collections.Generic;
+
+namespace org.matheval.Functions
+{
+ ///
+ /// Returns the year from a date
+ ///
+ public class yearFunction : IFunction
+ {
+ ///
+ /// Get Information
+ ///
+ /// FunctionDefs
+ public List GetInfo()
+ {
+ return new List
+ {
+ new FunctionDef(Afe_Common.Const_Year, new Type[] { typeof(string) }, typeof(decimal), 1)
+ };
+ }
+
+ ///
+ /// Execute
+ ///
+ /// args
+ /// dc
+ /// Value
+ public Object Execute(Dictionary args, ExpressionContext dc)
+ {
+ var dateTime = Afe_Common.ToDateTime(args[Afe_Common.Const_Key_One].ToString(), dc.WorkingCulture);
+ return Afe_Common.ToInteger(dateTime.Year, dc.WorkingCulture);
+ }
+ }
+}
diff --git a/Math expression eval/org.matheval/org.matheval.csproj b/Math expression eval/org.matheval/org.matheval.csproj
index 677a79e..39b3f02 100644
--- a/Math expression eval/org.matheval/org.matheval.csproj
+++ b/Math expression eval/org.matheval/org.matheval.csproj
@@ -1,7 +1,7 @@
- netcoreapp2.1;netcoreapp3.1;net35;net40;net45;net46;net461;net462;net47;net471;net472;net48;netstandard2.0
+ netstandard2.0;netstandard2.1
Library
Matheval
org.matheval