Skip to content

Perform set operations like difference, union and intersection on list of timeslots, modeled as a pair of Timespans - one for the time past some reference point in time when the slot opens and the other for how long the slot stays open

Notifications You must be signed in to change notification settings

goekboet/timeslot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Timeslot

To build the project:

dotnet restore && dotnet build

To run the testsuite:

dotnet test

Description

Model a timeslot as a tuple of two TimeSpan where the first is when the slot opens and the second how long the slot stays open. Take the difference, union and intersection of a single or a list of timeslots.

These functions will assume that the timeslots are sorted in descending order with regards to the open (first item in the tuple) timespan

Example:

// Minutes(x) is defined as TimeSpan.FromMinutes(x)
var first = new[] { (Minutes(60), Minutes(20)), (Minutes(90Minutes(20)) };
var second = new[] { (Minutes(70), Minutes(30)) 

// Show is a function (TimeSpan o, TimeSpan d) -> string 
var diff = Difference(first, second).Select(Show);
var union = Union(first, second).Select(Show);
var intersect = Intersection(first, second).Select(Show);

Console.WriteLine("Difference:");
foreach (var slot in diff) Console.WriteLine(slot);

Console.WriteLine("Union:");
foreach (var slot in union) Console.WriteLine(slot);

Console.WriteLine("Intersect:");
foreach (var slot in intersect) Console.WriteLine(slot);

// Will print:
// Difference:
// o: 01:00:00 d: 00:10:00
// o: 01:40:00 d: 00:10:00
// Union:
// o: 01:00:00 d: 00:50:00
// Intersect:
// o: 01:10:00 d: 00:10:00
// o: 01:30:00 d: 00:10:00

About

Perform set operations like difference, union and intersection on list of timeslots, modeled as a pair of Timespans - one for the time past some reference point in time when the slot opens and the other for how long the slot stays open

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages