-
-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Czech (cs-CZ) holiday strategy and natural time strategy, including tests.
- Loading branch information
1 parent
1d7dff7
commit d2f021b
Showing
4 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
src/DateTimeExtensions/NaturalText/CultureStrategies/CS_CZNaturalTimeStrategy.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,92 @@ | ||
using DateTimeExtensions.Common; | ||
using System; | ||
|
||
namespace DateTimeExtensions.NaturalText.CultureStrategies | ||
{ | ||
[Locale("cs-CZ")] | ||
public class CS_CZNaturalTimeStrategy : NaturalTimeStrategyBase | ||
{ | ||
protected override string YearText | ||
{ | ||
get { return "rok"; } | ||
} | ||
|
||
protected override string MonthText | ||
{ | ||
get { return "měsíc"; } | ||
} | ||
|
||
protected override string DayText | ||
{ | ||
get { return "den"; } | ||
} | ||
|
||
protected override string HourText | ||
{ | ||
get { return "hodina"; } | ||
} | ||
|
||
protected override string MinuteText | ||
{ | ||
get { return "minuta"; } | ||
} | ||
|
||
protected override string SecondText | ||
{ | ||
get { return "vteřina"; } | ||
} | ||
|
||
protected override string Pluralize(string text, int value) | ||
{ | ||
if (text.Equals("rok", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (value < 5) | ||
{ | ||
return "roky"; | ||
} | ||
return "let"; | ||
} | ||
if (text.Equals("měsíc", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (value < 5) | ||
{ | ||
return "měsíce"; | ||
} | ||
return "měsíců"; | ||
} | ||
if (text.Equals("den", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (value < 5) | ||
{ | ||
return "dny"; | ||
} | ||
return "dnů"; | ||
} | ||
if (text.Equals("hodina", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (value < 5) | ||
{ | ||
return "hodiny"; | ||
} | ||
return "hodin"; | ||
} | ||
if (text.Equals("minuta", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (value < 5) | ||
{ | ||
return "minuty"; | ||
} | ||
return "minut"; | ||
} | ||
if (text.Equals("vteřina", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (value < 5) | ||
{ | ||
return "vteřiny"; | ||
} | ||
return "vteřin"; | ||
} | ||
return text; | ||
} | ||
} | ||
} |
187 changes: 187 additions & 0 deletions
187
src/DateTimeExtensions/WorkingDays/CultureStrategies/CS_CZHolidayStrategy.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,187 @@ | ||
using DateTimeExtensions.Common; | ||
|
||
namespace DateTimeExtensions.WorkingDays.CultureStrategies | ||
{ | ||
[Locale("cs-CZ")] | ||
public class CS_CZHolidayStrategy : HolidayStrategyBase, IHolidayStrategy | ||
{ | ||
public CS_CZHolidayStrategy() | ||
{ | ||
// January 1 has two holidays | ||
this.InnerHolidays.Add(NewYearAndRestorationOfIndependence); | ||
// Good Friday has been a holiday since 2016. | ||
this.InnerHolidays.Add(GoodFridayCzechia); | ||
this.InnerHolidays.Add(ChristianHolidays.EasterMonday); | ||
this.InnerHolidays.Add(LabourDay); | ||
this.InnerHolidays.Add(VictoryDay); | ||
this.InnerHolidays.Add(CyrilAndMethodiusDay); | ||
this.InnerHolidays.Add(JanHusDay); | ||
this.InnerHolidays.Add(StatehoodDay); | ||
this.InnerHolidays.Add(CzechoslovakIndependenceDay); | ||
this.InnerHolidays.Add(FreedomAndDemocracyAndStudentsDay); | ||
// The main Christmas holiday is on December 24 while the 25 and 26 are also bank holidays. | ||
this.InnerHolidays.Add(ChristmasEve); | ||
this.InnerHolidays.Add(FirstChristmasDay); | ||
this.InnerHolidays.Add(SecondChristmasDay); | ||
} | ||
|
||
private static Holiday restorationOfIndependenceDay; | ||
public static Holiday NewYearAndRestorationOfIndependence | ||
{ | ||
get | ||
{ | ||
if (restorationOfIndependenceDay == null) | ||
{ | ||
restorationOfIndependenceDay = new FixedHoliday( | ||
"New Year's Day, Restoration Day of the Independent Czech State", 1, 1); | ||
} | ||
return restorationOfIndependenceDay; | ||
} | ||
} | ||
|
||
private static Holiday goodFridayYearDependant; | ||
public static Holiday GoodFridayCzechia | ||
{ | ||
get | ||
{ | ||
if (goodFridayYearDependant == null) | ||
{ | ||
goodFridayYearDependant = new YearDependantHoliday( | ||
year => year > 2015, ChristianHolidays.GoodFriday); | ||
} | ||
return goodFridayYearDependant; | ||
} | ||
} | ||
|
||
private static Holiday labourDay; | ||
public static Holiday LabourDay | ||
{ | ||
get | ||
{ | ||
if (labourDay == null) | ||
{ | ||
labourDay = new FixedHoliday("Labour Day", 5, 1); | ||
} | ||
return labourDay; | ||
} | ||
} | ||
|
||
private static Holiday victoryDay; | ||
public static Holiday VictoryDay | ||
{ | ||
get | ||
{ | ||
if (victoryDay == null) | ||
{ | ||
victoryDay = new FixedHoliday("Victory Day", 5, 8); | ||
} | ||
return victoryDay; | ||
} | ||
} | ||
|
||
private static Holiday cyrilAndMethodiusDay; | ||
public static Holiday CyrilAndMethodiusDay | ||
{ | ||
get | ||
{ | ||
if (cyrilAndMethodiusDay == null) | ||
{ | ||
cyrilAndMethodiusDay = new FixedHoliday("Saints Cyril and Methodius Day", 7, 5); | ||
} | ||
return cyrilAndMethodiusDay; | ||
} | ||
} | ||
|
||
private static Holiday janHusDay; | ||
public static Holiday JanHusDay | ||
{ | ||
get | ||
{ | ||
if (janHusDay == null) | ||
{ | ||
janHusDay = new FixedHoliday("Jan Hus Day", 7, 6); | ||
} | ||
return janHusDay; | ||
} | ||
} | ||
|
||
private static Holiday statehoodDay; | ||
public static Holiday StatehoodDay | ||
{ | ||
get | ||
{ | ||
if (statehoodDay == null) | ||
{ | ||
statehoodDay = new FixedHoliday("Czech Statehood Day", 9, 28); | ||
} | ||
return statehoodDay; | ||
} | ||
} | ||
|
||
private static Holiday czechoslovakIndependenceDay; | ||
public static Holiday CzechoslovakIndependenceDay | ||
{ | ||
get | ||
{ | ||
if (czechoslovakIndependenceDay == null) | ||
{ | ||
czechoslovakIndependenceDay = new FixedHoliday("Independent Czechoslovak State Day", 10, 28); | ||
} | ||
return czechoslovakIndependenceDay; | ||
} | ||
} | ||
|
||
private static Holiday freedomAndDemocracyDay; | ||
public static Holiday FreedomAndDemocracyAndStudentsDay | ||
{ | ||
get | ||
{ | ||
if (freedomAndDemocracyDay == null) | ||
{ | ||
freedomAndDemocracyDay = new FixedHoliday( | ||
"Struggle for Freedom and Democracy Day and International Students' Day", 11, 17); | ||
} | ||
return freedomAndDemocracyDay; | ||
} | ||
} | ||
|
||
private static Holiday christmasEve; | ||
public static Holiday ChristmasEve | ||
{ | ||
get | ||
{ | ||
if (christmasEve == null) | ||
{ | ||
christmasEve = new FixedHoliday("Christmas Eve", 12, 24); | ||
} | ||
return christmasEve; | ||
} | ||
} | ||
|
||
private static Holiday firstChristmasDay; | ||
public static Holiday FirstChristmasDay | ||
{ | ||
get | ||
{ | ||
if (firstChristmasDay == null) | ||
{ | ||
firstChristmasDay = new FixedHoliday("1st Christmas Day", 12, 25); | ||
} | ||
return firstChristmasDay; | ||
} | ||
} | ||
|
||
private static Holiday secondChristmasDay; | ||
public static Holiday SecondChristmasDay | ||
{ | ||
get | ||
{ | ||
if (secondChristmasDay == null) | ||
{ | ||
secondChristmasDay = new FixedHoliday("2nd Christmas Day", 12, 26); | ||
} | ||
return secondChristmasDay; | ||
} | ||
} | ||
} | ||
} |
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,57 @@ | ||
using DateTimeExtensions.WorkingDays; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace DateTimeExtensions.Tests | ||
{ | ||
[TestFixture] | ||
public class CsCzHolidaysTests | ||
{ | ||
private WorkingDayCultureInfo dateTimeCulture = new WorkingDayCultureInfo("cs-CZ"); | ||
|
||
[Test] | ||
public void Czechia_Has_13_HolidayDays() | ||
{ | ||
Assert.That(dateTimeCulture.Holidays.Count(), Is.EqualTo(13)); | ||
} | ||
|
||
[Test] | ||
[TestCase(2016)] | ||
[TestCase(2025)] | ||
[TestCase(2031)] | ||
public void Good_Friday_Is_A_Holiday_From_2016(int year) | ||
{ | ||
DateTime goodFriday = ChristianHolidays.GoodFriday.GetInstance(year).Value; | ||
Assert.That(goodFriday.IsHoliday(), Is.True); | ||
} | ||
|
||
[Test] | ||
[TestCase(2015)] | ||
[TestCase(2003)] | ||
[TestCase(1996)] | ||
public void Good_Friday_Is_Not_A_Holiday_Before_2016(int year) | ||
{ | ||
DateTime goodFriday = ChristianHolidays.GoodFriday.GetInstance(year).Value; | ||
Assert.That(goodFriday.IsWorkingDay(), Is.True); | ||
} | ||
|
||
[Test] | ||
[TestCase(2015, 1, 1)] | ||
[TestCase(2003, 5, 1)] | ||
[TestCase(1996, 5, 8)] | ||
[TestCase(1998, 7, 5)] | ||
[TestCase(1994, 7, 6)] | ||
[TestCase(1996, 9, 28)] | ||
[TestCase(2005, 10, 28)] | ||
[TestCase(2028, 11, 17)] | ||
[TestCase(2001, 12, 24)] | ||
[TestCase(2011, 12, 25)] | ||
[TestCase(2025, 12, 26)] | ||
public void Dates_Are_Correctly_Identified_As_Specific_Czech_Holidays(int year, int month, int day) | ||
{ | ||
DateTime holiday = new(year, month, day); | ||
Assert.That(holiday.IsHoliday(), Is.True); | ||
} | ||
} | ||
} |
Oops, something went wrong.