-
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from HERN1k/ua_culture
added ua culture
- Loading branch information
Showing
4 changed files
with
360 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/DateTimeExtensions/NaturalText/CultureStrategies/UK_UANaturalTimeStrategy.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,63 @@ | ||
using DateTimeExtensions.Common; | ||
|
||
namespace DateTimeExtensions.NaturalText.CultureStrategies | ||
{ | ||
[Locale("uk-UA")] | ||
public class UK_UANaturalTimeStrategy : NaturalTimeStrategyBase | ||
{ | ||
protected override string YearText | ||
{ | ||
get { return "рік"; } | ||
} | ||
|
||
protected override string MonthText | ||
{ | ||
get { return "місяць"; } | ||
} | ||
|
||
protected override string DayText | ||
{ | ||
get { return "день"; } | ||
} | ||
|
||
protected override string HourText | ||
{ | ||
get { return "година"; } | ||
} | ||
|
||
protected override string MinuteText | ||
{ | ||
get { return "хвилина"; } | ||
} | ||
|
||
protected override string SecondText | ||
{ | ||
get { return "секунда"; } | ||
} | ||
|
||
protected override string Pluralize(string text, int value) | ||
{ | ||
if (text.EndsWith("рік")) | ||
{ | ||
return "роки"; | ||
} | ||
|
||
if (text.EndsWith("день")) | ||
{ | ||
return "дні"; | ||
} | ||
|
||
if (text.EndsWith("ь")) | ||
{ | ||
return text.Substring(0, text.Length - 1) + "і"; | ||
} | ||
|
||
if (text.EndsWith("а")) | ||
{ | ||
return text.Substring(0, text.Length - 1) + "и"; | ||
} | ||
|
||
return text; | ||
} | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
src/DateTimeExtensions/WorkingDays/CultureStrategies/UK_UAHolidayStrategy.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,121 @@ | ||
using DateTimeExtensions.Common; | ||
|
||
namespace DateTimeExtensions.WorkingDays.CultureStrategies | ||
{ | ||
[Locale("uk-UA")] | ||
public class UK_UAHolidayStrategy : HolidayStrategyBase, IHolidayStrategy | ||
{ | ||
public UK_UAHolidayStrategy() | ||
{ | ||
this.InnerHolidays.Add(GlobalHolidays.NewYear); | ||
this.InnerHolidays.Add(WomensDay); | ||
this.InnerHolidays.Add(ChristianHolidays.Easter); | ||
this.InnerHolidays.Add(WorkersDay); | ||
this.InnerHolidays.Add(VictoryInEuropeDay); | ||
this.InnerHolidays.Add(ChristianHolidays.Pentecost); | ||
this.InnerHolidays.Add(ConstitutionDay); | ||
this.InnerHolidays.Add(StatehoodDay); | ||
this.InnerHolidays.Add(IndependenceDayOfUkraine); | ||
this.InnerHolidays.Add(DefendersDay); | ||
this.InnerHolidays.Add(ChristianHolidays.Christmas); | ||
} | ||
|
||
private static Holiday womensDay; | ||
|
||
public static Holiday WomensDay | ||
{ | ||
get | ||
{ | ||
if (womensDay == null) | ||
{ | ||
womensDay = new FixedHoliday("International Women's Day", 3, 8); | ||
} | ||
return womensDay; | ||
} | ||
} | ||
|
||
private static Holiday workersDay; | ||
|
||
public static Holiday WorkersDay | ||
{ | ||
get | ||
{ | ||
if (workersDay == null) | ||
{ | ||
workersDay = new FixedHoliday("International Workers' Day", 5, 1); | ||
} | ||
return workersDay; | ||
} | ||
} | ||
|
||
private static Holiday victoryInEuropeDay; | ||
|
||
public static Holiday VictoryInEuropeDay | ||
{ | ||
get | ||
{ | ||
if (victoryInEuropeDay == null) | ||
{ | ||
victoryInEuropeDay = new FixedHoliday("Victory in Europe Day", 5, 8); | ||
} | ||
return victoryInEuropeDay; | ||
} | ||
} | ||
|
||
private static Holiday constitutionDay; | ||
|
||
public static Holiday ConstitutionDay | ||
{ | ||
get | ||
{ | ||
if (constitutionDay == null) | ||
{ | ||
constitutionDay = new FixedHoliday("Constitution Day", 6, 28); | ||
} | ||
return constitutionDay; | ||
} | ||
} | ||
|
||
private static Holiday statehoodDay; | ||
|
||
public static Holiday StatehoodDay | ||
{ | ||
get | ||
{ | ||
if (statehoodDay == null) | ||
{ | ||
statehoodDay = new FixedHoliday("Statehood Day", 7, 15); | ||
} | ||
return statehoodDay; | ||
} | ||
} | ||
|
||
private static Holiday independenceDayOfUkraine; | ||
|
||
public static Holiday IndependenceDayOfUkraine | ||
{ | ||
get | ||
{ | ||
if (independenceDayOfUkraine == null) | ||
{ | ||
independenceDayOfUkraine = new FixedHoliday("Independence Day of Ukraine", 8, 24); | ||
} | ||
return independenceDayOfUkraine; | ||
} | ||
} | ||
|
||
private static Holiday defendersDay; | ||
|
||
public static Holiday DefendersDay | ||
{ | ||
get | ||
{ | ||
if (defendersDay == null) | ||
{ | ||
defendersDay = new FixedHoliday("Defenders Day", 10, 1); | ||
} | ||
return defendersDay; | ||
} | ||
} | ||
} | ||
} |
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,83 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using DateTimeExtensions.Export; | ||
using DateTimeExtensions.WorkingDays; | ||
using DateTimeExtensions.WorkingDays.CultureStrategies; | ||
|
||
using NUnit.Framework; | ||
|
||
#pragma warning disable NUnit2005 | ||
|
||
namespace DateTimeExtensions.Tests | ||
{ | ||
[TestFixture] | ||
public class UAHolidaysTests | ||
{ | ||
private WorkingDayCultureInfo dateTimeCulture = new WorkingDayCultureInfo("uk-UA"); | ||
|
||
[Test] | ||
public void UA_has_11_main_holidays() | ||
This comment has been minimized.
Sorry, something went wrong. |
||
{ | ||
Assert.AreEqual(11, dateTimeCulture.Holidays.Count()); | ||
} | ||
|
||
[Test] | ||
public void Easter2017_is_16_april() | ||
{ | ||
Assert.That(new DateTime(2017, 4, 16).IsHoliday(dateTimeCulture)); | ||
} | ||
|
||
[Test] | ||
public void Easter2018_is_1_april() | ||
{ | ||
Assert.That(new DateTime(2018, 4, 1).IsHoliday(dateTimeCulture)); | ||
} | ||
|
||
[Test] | ||
public void Test2() | ||
{ | ||
var holidaysStrategy = dateTimeCulture.LocateHolidayStrategy(dateTimeCulture.Name, null); | ||
|
||
Assert.AreEqual(typeof(UK_UAHolidayStrategy), holidaysStrategy.GetType()); | ||
var workingDaysStrategy = dateTimeCulture.LocateWorkingDayOfWeekStrategy(dateTimeCulture.Name, null); | ||
Assert.AreEqual(typeof(DefaultWorkingDayOfWeekStrategy), workingDaysStrategy.GetType()); | ||
} | ||
|
||
[Test] | ||
public void can_identify_VictoryInEuropeDay() | ||
{ | ||
var holiday = UK_UAHolidayStrategy.VictoryInEuropeDay; | ||
var day = new DateTime(2024, 5, 8); | ||
TestHoliday(holiday, day); | ||
} | ||
|
||
[Test] | ||
public void test_export() | ||
{ | ||
var easter = ChristianHolidays.Easter; | ||
var easter_1800 = easter.GetInstance(1800); | ||
var easter_2017 = easter.GetInstance(2017); | ||
var easter_2018 = easter.GetInstance(2018); | ||
var easter_2022 = easter.GetInstance(2022); | ||
var easter_2023 = easter.GetInstance(2023); | ||
var easter_2024 = easter.GetInstance(2024); | ||
var easter_2025 = easter.GetInstance(2025); | ||
|
||
TextWriter textwriter = new StringWriter(); | ||
var exporter = ExportHolidayFormatLocator.LocateByType(ExportType.OfficeHolidays); | ||
exporter.Export(dateTimeCulture, 2024, textwriter); | ||
var s = textwriter.ToString(); | ||
Assert.NotNull(s); | ||
} | ||
|
||
private void TestHoliday(Holiday holiday, DateTime dateOnGregorian) | ||
{ | ||
var holidayInstance = holiday.GetInstance(dateOnGregorian.Year); | ||
Assert.True(holidayInstance.HasValue); | ||
Assert.AreEqual(dateOnGregorian, holidayInstance.Value); | ||
Assert.True(holiday.IsInstanceOf(dateOnGregorian)); | ||
} | ||
} | ||
} |
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,93 @@ | ||
using System; | ||
|
||
using DateTimeExtensions.NaturalText; | ||
|
||
using NUnit.Framework; | ||
|
||
#pragma warning disable NUnit2005 | ||
|
||
namespace DateTimeExtensions.Tests | ||
{ | ||
[TestFixture] | ||
public class UK_UANaturalTimeTests | ||
{ | ||
private NaturalTextCultureInfo ua_ci = new NaturalTextCultureInfo("uk-UA"); | ||
private DateTime fromTime = new DateTime(2024, 5, 8, 9, 41, 0); | ||
|
||
[Test] | ||
public void can_tranlate_to_natural_text() | ||
{ | ||
var toTime = fromTime.AddHours(2).AddMinutes(45); | ||
|
||
var naturalText = fromTime.ToNaturalText(toTime, false, ua_ci); | ||
|
||
Assert.IsNotNull(naturalText); | ||
Assert.IsNotEmpty(naturalText); | ||
Assert.AreEqual("2 години", naturalText); | ||
} | ||
|
||
[Test] | ||
public void can_tranlate_to_natural_text_rounded() | ||
{ | ||
var toTime = fromTime.AddHours(2).AddMinutes(45); | ||
|
||
var naturalText = fromTime.ToNaturalText(toTime, true, ua_ci); | ||
|
||
Assert.IsNotNull(naturalText); | ||
Assert.IsNotEmpty(naturalText); | ||
Assert.AreEqual("3 години", naturalText); | ||
} | ||
|
||
[Test] | ||
public void can_tranlate_to_exact_natural_text_full() | ||
{ | ||
var toTime = fromTime | ||
.AddSeconds(6) | ||
.AddMinutes(5) | ||
.AddHours(4) | ||
.AddDays(3) | ||
.AddMonths(2) | ||
.AddYears(2); | ||
|
||
var naturalText = fromTime.ToExactNaturalText(toTime, ua_ci); | ||
|
||
Assert.NotNull(naturalText); | ||
Assert.IsNotEmpty(naturalText); | ||
Assert.AreEqual("2 роки, 2 місяці, 3 дні, 4 години, 5 хвилини, 6 секунди", naturalText); | ||
} | ||
|
||
[Test] | ||
public void can_pluralize_years() | ||
{ | ||
var toTime_plural = fromTime.AddYears(2); | ||
var toTime_single = fromTime.AddYears(1); | ||
|
||
var naturalText_plural = fromTime.ToNaturalText(toTime_plural, true, ua_ci); | ||
var naturalText_single = fromTime.ToNaturalText(toTime_single, true, ua_ci); | ||
|
||
Assert.IsNotNull(naturalText_plural); | ||
Assert.IsNotEmpty(naturalText_plural); | ||
Assert.IsNotNull(naturalText_single); | ||
Assert.IsNotEmpty(naturalText_single); | ||
Assert.AreEqual("2 роки", naturalText_plural); | ||
Assert.AreEqual("1 рік", naturalText_single); | ||
} | ||
|
||
[Test] | ||
public void can_pluralize_months() | ||
{ | ||
var toTime_plural = fromTime.AddMonths(2); | ||
var toTime_single = fromTime.AddMonths(1); | ||
|
||
var naturalText_plural = fromTime.ToNaturalText(toTime_plural, true, ua_ci); | ||
var naturalText_single = fromTime.ToNaturalText(toTime_single, true, ua_ci); | ||
|
||
Assert.IsNotNull(naturalText_plural); | ||
Assert.IsNotEmpty(naturalText_plural); | ||
Assert.IsNotNull(naturalText_single); | ||
Assert.IsNotEmpty(naturalText_single); | ||
Assert.AreEqual("2 місяці", naturalText_plural); | ||
Assert.AreEqual("1 місяць", naturalText_single); | ||
} | ||
} | ||
} |
En