-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moved HolidayService to be Consultant dependant. (#165)
- Loading branch information
1 parent
b1c4730
commit 92f5b66
Showing
8 changed files
with
121 additions
and
125 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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
using Core.DomainModels; | ||
using Core.Services; | ||
using PublicHoliday; | ||
|
||
namespace Api.Organisation; | ||
|
||
public static class OrganisationHolidayExtensions | ||
{ | ||
public static int GetTotalHolidaysOfWeek(this Organization organization, int year, int week) | ||
{ | ||
var datesOfThisWeek = DateService.GetDatesInWorkWeek(year, week); | ||
return datesOfThisWeek.Count(organization.IsHoliday); | ||
} | ||
|
||
private static bool IsHoliday(this Organization organization, DateOnly day) | ||
{ | ||
return organization.IsPublicHoliday(day) || organization.IsChristmasHoliday(day); | ||
} | ||
|
||
private static bool IsPublicHoliday(this Organization organization, DateOnly day) | ||
{ | ||
var publicHoliday = organization.GetPublicHoliday(); | ||
var isPublicHoliday = publicHoliday.IsPublicHoliday(day.ToDateTime(TimeOnly.MinValue)); | ||
return isPublicHoliday || organization.IsChristmasHoliday(day); | ||
} | ||
|
||
private static PublicHolidayBase GetPublicHoliday(this Organization organization) | ||
{ | ||
var country = organization.Country; | ||
|
||
return country switch | ||
{ | ||
"norway" => new NorwayPublicHoliday(), | ||
"sweden" => new SwedenPublicHoliday(), | ||
_ => new NorwayPublicHoliday() | ||
}; | ||
} | ||
|
||
private static bool IsChristmasHoliday(this Organization organization, DateOnly date) | ||
{ | ||
if (organization.HasVacationInChristmas) return false; | ||
|
||
var startDate = new DateOnly(date.Year, 12, 24); | ||
var endDate = new DateOnly(date.Year, 12, 31); | ||
|
||
return date >= startDate && date <= endDate; | ||
} | ||
} |
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