WorkTimeCalculator 1.0.0
See the version list below for details.
dotnet add package WorkTimeCalculator --version 1.0.0
NuGet\Install-Package WorkTimeCalculator -Version 1.0.0
<PackageReference Include="WorkTimeCalculator" Version="1.0.0" />
paket add WorkTimeCalculator --version 1.0.0
#r "nuget: WorkTimeCalculator, 1.0.0"
// Install WorkTimeCalculator as a Cake Addin #addin nuget:?package=WorkTimeCalculator&version=1.0.0 // Install WorkTimeCalculator as a Cake Tool #tool nuget:?package=WorkTimeCalculator&version=1.0.0
WorkTimeCalculator
A utility library to calculate work time within a period, with a configurable work schedule and holidays.
Support
This project is built using C# .Net Core 3.1 class library but it can be ported and compiled with C# .Net
How To Use
After importing the library in the dependencies of your project, create an instance of the calculator with the work schedule and holidays configuration
var calculator = new WorkTimeCalculator(MySchedule, MyHolidays);
You can also change the configuration if needed by calling SetConfigurations
calculator.SetConfigurations(MySchedule, MyHolidays);
Then call the CalculateWorkTime
function
TimeSpan result = calculator.CalculateWorkTime(
new DateTime(2021, 6, 1, 10, 30, 0),
new DateTime(2021, 6, 10, 15, 30, 0),
true //Optional bool parameter to exclude holidays from calculation [default: true]
);
Work Schedule Configuration Example
Dictionary<DayOfWeek, List<WorkShift>> MySchedule = new Dictionary<DayOfWeek, List<WorkShift>>() {
{ DayOfWeek.Sunday, new List<WorkShift>(){
new WorkShift(){ Start = new TimeSpan(9,0,0), End = new TimeSpan(13,0,0)},
new WorkShift(){ Start = new TimeSpan(14,0,0), End = new TimeSpan(18,0,0)}
} },
{ DayOfWeek.Monday, new List<WorkShift>(){
new WorkShift(){ Start = new TimeSpan(9,0,0), End = new TimeSpan(13,0,0)},
new WorkShift(){ Start = new TimeSpan(14,0,0), End = new TimeSpan(18,0,0)}
} },
{ DayOfWeek.Tuesday, new List<WorkShift>(){
new WorkShift(){ Start = new TimeSpan(9,0,0), End = new TimeSpan(13,0,0)},
new WorkShift(){ Start = new TimeSpan(14,0,0), End = new TimeSpan(18,0,0)}
} },
{ DayOfWeek.Wednesday, new List<WorkShift>(){
new WorkShift(){ Start = new TimeSpan(9,0,0), End = new TimeSpan(13,0,0)},
new WorkShift(){ Start = new TimeSpan(14,0,0), End = new TimeSpan(18,0,0)}
} },
{ DayOfWeek.Thursday, new List<WorkShift>(){
new WorkShift(){ Start = new TimeSpan(9,0,0), End = new TimeSpan(13,0,0)},
new WorkShift(){ Start = new TimeSpan(14,0,0), End = new TimeSpan(18,0,0)}
} }
};
Holidays Configuration Example
List<HolidayConfig> MyHolidays = new List<HolidayConfig>() {
new HolidayConfig (){ Start = new DateTime(2021, 6, 2), End = new DateTime(2021, 6, 8) },
new HolidayConfig (){ Start = new DateTime(2021, 7, 2), End = new DateTime(2021, 7, 8) },
new HolidayConfig (){ Start = new DateTime(2021, 8, 2), End = new DateTime(2021, 8, 8) }
};
Notes
- The returned type is
TimeSpan
so the user can extract the value in any time format as needed (hours, minutes, seconds ...etc) - The accuracy of the calculated time is in seconds
- Holidays date configuration is all inclusive of the full days
- If a day was not configured in the schedule or it has no shifts (or shifts total time value is 0) then it is a non working day
- Configuration is not checked for validity and it is the responsilbility of the developer, if there are intersections between shifts or holidays it can lead to wrong results
- The performance of this utility is almost
O(n*k)
wheren
is the maximum number of shifts per day, andk
is the number of holidays within a single period
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.