-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
216 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
<PropertyGroup> | ||
<Authors>Paolo Innocenti</Authors> | ||
<Copyright>Copyright 2021 (c) Paolo Innocenti - [email protected] </Copyright> | ||
<AssemblyVersion>2.0.8</AssemblyVersion> | ||
<FileVersion>2.0.8</FileVersion> | ||
<Version>2.0.8</Version> | ||
<AssemblyVersion>2.0.9</AssemblyVersion> | ||
<FileVersion>2.0.9</FileVersion> | ||
<Version>2.0.9</Version> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)'=='Debug'"> | ||
|
90 changes: 90 additions & 0 deletions
90
PH.WorkingDaysAndTime/PH.WorkingDaysAndTimeUtility.UnitTest/MultiCalculatedHolidaysTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using PH.WorkingDaysAndTimeUtility.Configuration; | ||
using Xunit; | ||
|
||
namespace PH.WorkingDaysAndTimeUtility.UnitTest | ||
{ | ||
public class MultiCalculatedHolidaysTest : BaseTest | ||
{ | ||
[Fact] | ||
public void TestWorkingOnSaturdayIfOdd() | ||
{ | ||
var wts1 = new WorkTimeSpan() { Start = new TimeSpan(9, 0, 0), End = new TimeSpan(13, 0, 0) }; | ||
|
||
var wts2 = new WorkTimeSpan() { Start = new TimeSpan(14, 0, 0), End = new TimeSpan(18, 0, 0) }; | ||
var wts = new List<WorkTimeSpan>() { wts1, wts2 }; | ||
var week = new WeekDaySpan() | ||
{ | ||
WorkDays = new Dictionary<DayOfWeek, WorkDaySpan>() | ||
{ | ||
{DayOfWeek.Monday, new WorkDaySpan() {TimeSpans = wts }} | ||
, | ||
{DayOfWeek.Tuesday, new WorkDaySpan() {TimeSpans = wts}} | ||
, | ||
{DayOfWeek.Wednesday, new WorkDaySpan() {TimeSpans = wts}} | ||
, | ||
{DayOfWeek.Thursday, new WorkDaySpan() {TimeSpans = wts}} | ||
, | ||
{DayOfWeek.Friday, new WorkDaySpan() {TimeSpans = wts}} , | ||
{DayOfWeek.Saturday, new WorkDaySpan() {TimeSpans = wts}} | ||
} | ||
}; | ||
|
||
var italians = GetItalianHolidaysWithNoEasterMonday(); | ||
italians.Add(new EasterMonday()); | ||
italians.Add(new HoliDay(1, 12)); | ||
italians.Add(new WorkingOnSaturdayIfOdd()); | ||
|
||
var utility = new PH.WorkingDaysAndTimeUtility.WorkingDaysAndTimeUtility(week, italians); | ||
|
||
var aSaturday = new DateTime(2021, 8, 7); | ||
var t1 = utility.IsAWorkDay(aSaturday); | ||
var t2 = utility.IsAWorkDay(aSaturday.AddDays(7)); | ||
var t3 = utility.IsAWorkDay(aSaturday.AddDays(14)); | ||
var t4 = utility.IsAWorkDay(aSaturday.AddDays(21)); | ||
|
||
Assert.False(t1); | ||
Assert.False(t3); | ||
Assert.True(t2); | ||
Assert.True(t4); | ||
|
||
} | ||
} | ||
|
||
public class WorkingOnSaturdayIfOdd : MultiCalculatedHoliDay | ||
{ | ||
public WorkingOnSaturdayIfOdd() : base(0, 0) | ||
{ | ||
} | ||
|
||
public override Type GetHolyDayType() => typeof(WorkingOnSaturdayIfOdd); | ||
|
||
/// <summary>Calculates the list of MultiCalculatedHoliDays for the given year.</summary> | ||
/// <param name="year">The year.</param> | ||
/// <returns></returns> | ||
public override List<DateTime> CalculateList(int year) | ||
{ | ||
var first = new DateTime(year, 1, 1, 0, 0, 0); | ||
var last = new DateTime(year +1, 1, 1, 0, 0, 0); | ||
CultureInfo myCI = new CultureInfo("it-IT"); | ||
var baseHolidays = new List<DateTime>(); | ||
while (first < last) | ||
{ | ||
if (first.DayOfWeek == DayOfWeek.Saturday) | ||
{ | ||
var weekNumber = myCI.Calendar.GetWeekOfYear(first, CalendarWeekRule.FirstDay, DayOfWeek.Monday); | ||
if (weekNumber % 2 == 0) | ||
{ | ||
baseHolidays.Add(first); | ||
} | ||
} | ||
|
||
first = first.AddDays(1); | ||
} | ||
|
||
return baseHolidays; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,13 @@ | |
|
||
The application works only counting the dates forward and it is assumed that the date entered as the first parameter is a working day.</Description> | ||
<PackageReleaseNotes> | ||
Fix time splitting bugs. | ||
Now able to determine if given date is holyday | ||
Now able to add multi-calculated holidays to your configuration | ||
</PackageReleaseNotes> | ||
|
||
|
||
<PackageTags>work-days,DateTime,work-hours,work-minutes,work-DateTime,holiday,timespan, time-slices</PackageTags> | ||
<PackageTags>work-days,DateTime,work-hours,work-minutes,work-DateTime,holiday,timespan, time-slices, holiday</PackageTags> | ||
|
||
<PackageVersion>2.0.8</PackageVersion> | ||
<PackageVersion>2.0.9</PackageVersion> | ||
<Authors>Paolo Innocenti</Authors> | ||
<Copyright>Copyright PH 2021 (c) [email protected]. All rights reserved.</Copyright> | ||
<RepositoryUrl>https://github.com/paonath/PH.WorkingDaysAndTime</RepositoryUrl> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters