WorkTimeCalculator 1.0.4.2
See the version list below for details.
dotnet add package WorkTimeCalculator --version 1.0.4.2
NuGet\Install-Package WorkTimeCalculator -Version 1.0.4.2
<PackageReference Include="WorkTimeCalculator" Version="1.0.4.2" />
paket add WorkTimeCalculator --version 1.0.4.2
#r "nuget: WorkTimeCalculator, 1.0.4.2"
// Install WorkTimeCalculator as a Cake Addin #addin nuget:?package=WorkTimeCalculator&version=1.0.4.2 // Install WorkTimeCalculator as a Cake Tool #tool nuget:?package=WorkTimeCalculator&version=1.0.4.2
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
The package is available for multiple frameworks as a NuGet on NuGet.org and you can also use the following Package Manager command to add it to your project
Install-Package WorkTimeCalculator
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 | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 is compatible. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 2.0
- No dependencies.
-
.NETCoreApp 2.2
- No dependencies.
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.6.1
- No dependencies.
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Description added to functions (enhanced)