diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..3997da4
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,2 @@
+language: csharp
+solution: CSharp/ZgTimeTable/ZgTimeTable.sln
diff --git a/CSharp/ZgTimeTable/ZgTimeTable.sln b/CSharp/ZgTimeTable/ZgTimeTable.sln
index 5efd3d0..e3f005f 100644
--- a/CSharp/ZgTimeTable/ZgTimeTable.sln
+++ b/CSharp/ZgTimeTable/ZgTimeTable.sln
@@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZgTimeTable", "ZgTimeTable\ZgTimeTable.csproj", "{5B4D731F-2351-4BD7-B292-CFF3C2F565D3}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZgTimeTableTests", "ZgTimeTableTests\ZgTimeTableTests.csproj", "{F8D754CC-B9B5-43CB-82BB-F87327FACCF7}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
{5B4D731F-2351-4BD7-B292-CFF3C2F565D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B4D731F-2351-4BD7-B292-CFF3C2F565D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B4D731F-2351-4BD7-B292-CFF3C2F565D3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F8D754CC-B9B5-43CB-82BB-F87327FACCF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F8D754CC-B9B5-43CB-82BB-F87327FACCF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F8D754CC-B9B5-43CB-82BB-F87327FACCF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F8D754CC-B9B5-43CB-82BB-F87327FACCF7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/CSharp/ZgTimeTable/ZgTimeTable/TimeTable.cs b/CSharp/ZgTimeTable/ZgTimeTable/TimeTable.cs
index 5e699f8..ccd845e 100644
--- a/CSharp/ZgTimeTable/ZgTimeTable/TimeTable.cs
+++ b/CSharp/ZgTimeTable/ZgTimeTable/TimeTable.cs
@@ -82,7 +82,7 @@ private long findNearest(Session[] Sessions, Session[] Exceptions, long time)
{
foreach (Session session in Sessions)
{
- if (!session.isInPeriod(time))
+ if (session.isFinished(time))
continue;
long s;
@@ -140,7 +140,7 @@ private long findNearest(Session[] Sessions, Session[] Exceptions, long time)
private static bool isInSession(Session session, long time)
{
- if (time < session.Start || (session.End > 0 && session.End < time))
+ if (!session.isInPeriod(time))
{
return false;
}
@@ -206,17 +206,26 @@ public long remaining(long time)
long r = e - t;
return r > 0 ? r : 0;
}
- public bool isInPeriod(long time)
+ public bool isFinished(long time)
{
long e;
if (Cycle == 0 && End == 0)
+ {
e = Start + Duration;
+ }
else if (End == 0)
+ {
e = long.MaxValue;
+ }
else
+ {
e = End;
-
- return time >= Start && time < e;
+ }
+ return time >= e;
+ }
+ public bool isInPeriod(long time)
+ {
+ return time >= Start && !isFinished(time);
}
}
}
diff --git a/CSharp/ZgTimeTable/ZgTimeTableTests/Properties/AssemblyInfo.cs b/CSharp/ZgTimeTable/ZgTimeTableTests/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..d449417
--- /dev/null
+++ b/CSharp/ZgTimeTable/ZgTimeTableTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ZgTimeTableTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ZgTimeTableTests")]
+[assembly: AssemblyCopyright("Copyright © 2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("f8d754cc-b9b5-43cb-82bb-f87327faccf7")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/CSharp/ZgTimeTable/ZgTimeTableTests/TimeTableTests.cs b/CSharp/ZgTimeTable/ZgTimeTableTests/TimeTableTests.cs
new file mode 100644
index 0000000..9620632
--- /dev/null
+++ b/CSharp/ZgTimeTable/ZgTimeTableTests/TimeTableTests.cs
@@ -0,0 +1,91 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using ZgTimeTable;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZgTimeTable.Tests
+{
+ [TestClass()]
+ public class TimeTableTests
+ {
+ private static readonly DateTime Epoch = new DateTime(1970, 1, 1);
+
+ [TestMethod()]
+ public void TimeTableTest()
+ {
+ TimeTable tt = new TimeTable()
+ {
+ Sessions = new[]
+ {
+ new Session
+ {
+ Start = 1498867200000,
+ End = 1499000400000,
+ Duration = 3600000,
+ Cycle = 7200000
+ },
+ new Session
+ {
+ Start = 1498867200000,
+ End = 1499000400000,
+ Duration = 3600000,
+ Cycle = 0
+ }
+ },
+ Exceptions = new[]
+ {
+ new Session
+ {
+ Start = 1498867200000,
+ End = 1499000400000,
+ Duration = 1800000,
+ Cycle = 0
+ },
+ new Session
+ {
+ Start = 1498867200000,
+ End = 1499000400000,
+ Duration = 900000,
+ Cycle = 3600000
+ }
+ }
+
+ };
+
+ Assert.IsFalse(tt.isOpen(GetMilis(new DateTime(2017, 4, 1, 0, 1, 0))),
+ "A time before start of sessions is returning true!");
+
+ Assert.IsTrue(tt.isOpen(GetMilis(new DateTime(2017, 7, 1, 0, 30, 1))),
+ "A correct time is not returning true near begin!");
+
+ Assert.IsTrue(tt.isOpen(GetMilis(new DateTime(2017, 7, 1, 0, 42, 0))),
+ "A correct time is not returning true in between!");
+
+ Assert.IsTrue(tt.isOpen(GetMilis(new DateTime(2017, 7, 1, 2, 59, 59))),
+ "A correct time is not returning true in the end!");
+
+ Assert.IsTrue(tt.isOpen(GetMilis(new DateTime(2017, 7, 1, 0, 32, 0))),
+ "A correct time is not returning true!");
+
+ Assert.IsFalse(tt.isOpen(GetMilis(new DateTime(2017, 7, 1, 0, 20, 0))),
+ "Single time TimeTable Exceptions are not handled correctly!");
+
+ Assert.IsFalse(tt.isOpen(GetMilis(new DateTime(2017, 7, 1, 1, 20, 0))),
+ "Single time TimeTable Exceptions are not handled correctly and repeats!");
+
+ Assert.IsFalse(tt.isOpen(GetMilis(new DateTime(2017, 7, 1, 2, 11, 0))),
+ "Repeative TimeTable Exceptions are not handled correctly!");
+
+ Assert.IsFalse(tt.isOpen(GetMilis(new DateTime(2017, 7, 1, 1, 2, 0))),
+ "A closed time is returning true!");
+
+ Assert.IsFalse(tt.isOpen(GetMilis(new DateTime(2018, 7, 1, 3, 5, 0))),
+ "A time after end is returning true!");
+ }
+
+ public long GetMilis(DateTime dt) => (long) dt.Subtract(Epoch).TotalMilliseconds;
+ }
+}
\ No newline at end of file
diff --git a/CSharp/ZgTimeTable/ZgTimeTableTests/UnitTestingShim.cs b/CSharp/ZgTimeTable/ZgTimeTableTests/UnitTestingShim.cs
new file mode 100644
index 0000000..a469839
--- /dev/null
+++ b/CSharp/ZgTimeTable/ZgTimeTableTests/UnitTestingShim.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections;
+
+namespace Microsoft.VisualStudio.TestTools.UnitTesting
+{
+ public class Placeholder { }
+ public class TestClassAttribute : NUnit.Framework.TestFixtureAttribute
+ {
+ }
+ public class TestInitializeAttribute : NUnit.Framework.SetUpAttribute
+ {
+ }
+ public class TestMethodAttribute : NUnit.Framework.TestAttribute
+ {
+ }
+ public class TestCleanupAttribute : NUnit.Framework.TearDownAttribute
+ {
+ }
+ public class IgnoreAttribute : NUnit.Framework.IgnoreAttribute
+ {
+ }
+ public class ExpectedExceptionAttribute : NUnit.Framework.ExpectedExceptionAttribute
+ {
+ public ExpectedExceptionAttribute(Type exceptionType) : this(exceptionType, null)
+ {
+ }
+ public ExpectedExceptionAttribute(Type exceptionType, string message) : base(exceptionType)
+ {
+ UserMessage = message;
+ }
+ }
+ public class TestContext : NUnit.Framework.TestContext
+ {
+ public TestContext(IDictionary dictionary) : base(dictionary)
+ {
+ }
+ }
+ public class Assert : NUnit.Framework.Assert
+ {
+ public static void IsInstanceOfType(object obj, Type type)
+ {
+ NUnit.Framework.Assert.IsInstanceOfType(type, obj, null);
+ }
+ public static void IsInstanceOfType(object obj, Type type, string message)
+ {
+ NUnit.Framework.Assert.IsInstanceOfType(type, obj, message);
+ }
+ }
+}
\ No newline at end of file
diff --git a/CSharp/ZgTimeTable/ZgTimeTableTests/ZgTimeTableTests.csproj b/CSharp/ZgTimeTable/ZgTimeTableTests/ZgTimeTableTests.csproj
new file mode 100644
index 0000000..b0e93b6
--- /dev/null
+++ b/CSharp/ZgTimeTable/ZgTimeTableTests/ZgTimeTableTests.csproj
@@ -0,0 +1,94 @@
+
+
+
+ Debug
+ AnyCPU
+ {F8D754CC-B9B5-43CB-82BB-F87327FACCF7}
+ Library
+ Properties
+ ZgTimeTableTests
+ ZgTimeTableTests
+ v4.6.1
+ 512
+ {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ 10.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
+ False
+ UnitTest
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\nunit.framework.2.63.0\lib\nunit.framework.dll
+ True
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {5B4D731F-2351-4BD7-B292-CFF3C2F565D3}
+ ZgTimeTable
+
+
+
+
+
+
+
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+ False
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CSharp/ZgTimeTable/ZgTimeTableTests/packages.config b/CSharp/ZgTimeTable/ZgTimeTableTests/packages.config
new file mode 100644
index 0000000..e4aace1
--- /dev/null
+++ b/CSharp/ZgTimeTable/ZgTimeTableTests/packages.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 97e9fd8..3815524 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,7 @@
# Zigor Time Tables
+
+[](https://travis-ci.org/Resaneh24/ZigorTimeTable)
+
Zigor time table is a model for __Offline__ calculation of recurring time tables with minimal data structure and incredible performance.
Time tables in Zigor are completely flexible.