Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2 of Nager.Date #601

Merged
merged 144 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
ffb0cea
optimize code structure
tinohager Feb 28, 2024
82e3605
remove long weekend logic
tinohager Feb 28, 2024
c61d1f5
change code structure
tinohager Feb 28, 2024
a42eba5
optimize code structure
tinohager Feb 28, 2024
3ec44b2
optimize code structure
tinohager Feb 28, 2024
c94c9ff
optimize code
tinohager Feb 28, 2024
ca5d90c
Optimize class naming, optimize code structure
tinohager Feb 28, 2024
02da96e
add logic documentation
tinohager Feb 28, 2024
ff9fcd6
optimize summary
tinohager Feb 29, 2024
e045fc4
optimize code structure
tinohager Feb 29, 2024
54ad7b9
Optimize ReligiousProviders
tinohager Feb 29, 2024
023e283
Start migrate first countries
tinohager Feb 29, 2024
3142c52
migrate countries
tinohager Mar 1, 2024
3827420
migrate countries
tinohager Mar 1, 2024
a81a0c5
migrate canada
tinohager Mar 1, 2024
9246c75
cleanup migration
tinohager Mar 1, 2024
e64fa5e
migrate chile
tinohager Mar 1, 2024
cb39132
migrate china
tinohager Mar 1, 2024
6529972
migrate Costa Rica
tinohager Mar 1, 2024
9ddb07c
migrate Croatia
tinohager Mar 1, 2024
d498325
migrate Cuba (wip)
tinohager Mar 1, 2024
2c1f7df
migrate Cuba
tinohager Mar 1, 2024
f3800bb
migrate Cyprus
tinohager Mar 1, 2024
ee75576
migrate Czech Republic
tinohager Mar 1, 2024
56fc37c
migrate Colombia
tinohager Mar 1, 2024
8135ba0
migrate Denmark
tinohager Mar 1, 2024
1ee735a
migrate Dominican Republic
tinohager Mar 1, 2024
4642d46
migrate Ecuador
tinohager Mar 1, 2024
803489c
migrate Egypt
tinohager Mar 1, 2024
1243c2d
migrate Estonia
tinohager Mar 1, 2024
8132afb
migrate Faroe Islands
tinohager Mar 1, 2024
432c401
migrate Finland
tinohager Mar 1, 2024
229a156
migrate France
tinohager Mar 1, 2024
336842e
migrate Gabon
tinohager Mar 1, 2024
3ba0490
migrate Gambia
tinohager Mar 1, 2024
81533d7
migrate Gibraltar
tinohager Mar 1, 2024
67eda7e
migrate Greece
tinohager Mar 1, 2024
58b5905
migrate Grenada
tinohager Mar 1, 2024
a2e6a26
migrate Guatemala
tinohager Mar 1, 2024
7c3c7bd
migrate Guernsey
tinohager Mar 1, 2024
4ebc89f
cleanup
tinohager Mar 1, 2024
3250ff8
migrate Guyana
tinohager Mar 1, 2024
cf14fba
migrate Haiti
tinohager Mar 1, 2024
7f513bf
migrate Honduras
tinohager Mar 1, 2024
d8cfa9a
migrate Hungary
tinohager Mar 1, 2024
d0b0cba
migrate Iceland
tinohager Mar 1, 2024
4b1ee26
migrate Indonesia
tinohager Mar 1, 2024
edcea59
migrate Ireland
tinohager Mar 1, 2024
9380061
cleanup code
tinohager Mar 1, 2024
5f0f762
Update IndonesiaHolidayProvider.cs
tinohager Mar 1, 2024
0e5c769
migrate Italy
tinohager Mar 2, 2024
4e85c79
migrate Jamaica
tinohager Mar 2, 2024
85d4876
Update JamaicaHolidayProvider.cs
tinohager Mar 2, 2024
6447d30
migrate Japan
tinohager Mar 2, 2024
e72c1e7
migrate Jersey
tinohager Mar 2, 2024
0fa75c6
migrate Latvia
tinohager Mar 2, 2024
2da6fc9
migrate Lesotho
tinohager Mar 2, 2024
ed3dd14
migrate Liechtenstein
tinohager Mar 2, 2024
f600e81
migrate Lithuania
tinohager Mar 2, 2024
7335633
migrate Luxembourg
tinohager Mar 2, 2024
2fb8fbf
migrate Macedonia
tinohager Mar 2, 2024
56928b6
migrate Madagascar
tinohager Mar 2, 2024
4380f3a
migrate Malta
tinohager Mar 2, 2024
e41ca63
migrate Mexico
tinohager Mar 2, 2024
0e2f1b6
migrate Moldova
tinohager Mar 2, 2024
e937cb2
migrate Panama
tinohager Mar 2, 2024
9ffae10
migrate Norway
tinohager Mar 2, 2024
bea8394
migrate Niger
tinohager Mar 2, 2024
cb8d847
migrate Nicaragua
tinohager Mar 2, 2024
c856df1
cleanup code
tinohager Mar 2, 2024
33bb44a
migrate Namibia
tinohager Mar 2, 2024
7ac2538
migrate Mozambique
tinohager Mar 2, 2024
28ee7a2
migrate Morocco
tinohager Mar 2, 2024
ae64802
migrate Mongolia
tinohager Mar 2, 2024
3490a7b
fix typo failure
tinohager Mar 2, 2024
8392c54
remove .net 6 support
tinohager Mar 2, 2024
3a13e81
migrate Slovakia
tinohager Mar 3, 2024
0cb8526
migrate Slovenia
tinohager Mar 3, 2024
778f575
migrate Svalbard and Jan Mayen
tinohager Mar 3, 2024
ff09110
migrate Tunisia
tinohager Mar 3, 2024
f117268
migrate Ukraine
tinohager Mar 3, 2024
868f3fa
migrate Uruguay
tinohager Mar 3, 2024
ee75a6a
migrate Vatican City
tinohager Mar 3, 2024
f087499
migrate Vietnam
tinohager Mar 3, 2024
29bb134
migrate Zimbabwe
tinohager Mar 3, 2024
09021bc
migrate Monaco
tinohager Mar 3, 2024
d4de23b
cleanup provider
tinohager Mar 3, 2024
0c0066e
migrate Netherlands
tinohager Mar 3, 2024
50d5f5d
migrate nigeria
tinohager Mar 3, 2024
882f8a5
migrate Papua New Guinea
tinohager Mar 3, 2024
5a576bf
migrate Paraguay
tinohager Mar 3, 2024
e09adcb
migrate Peru
tinohager Mar 3, 2024
638fb15
migrate Poland
tinohager Mar 3, 2024
2adc4dc
small code fix
tinohager Mar 3, 2024
97cea80
migrate Montenegro
tinohager Mar 3, 2024
5fb2b33
migrate Serbia
tinohager Mar 3, 2024
aa50606
migrate Romania
tinohager Mar 3, 2024
dd3ecca
migrate Sweden
tinohager Mar 3, 2024
a5c8d3e
optimize code
tinohager Mar 3, 2024
dc5ffff
migrate Montserrat
tinohager Mar 3, 2024
ce1e9e8
migrate South Africa
tinohager Mar 3, 2024
120693b
code cleanup
tinohager Mar 3, 2024
a6fe783
migrate Greenland
tinohager Mar 4, 2024
1249b11
migrate San Marino
tinohager Mar 4, 2024
c0b2a1b
migrate Puerto Rico
tinohager Mar 4, 2024
1b3fa4d
cleanup code
tinohager Mar 4, 2024
89dff98
migrate Portugal
tinohager Mar 4, 2024
9550eef
migrate Suriname
tinohager Mar 4, 2024
95fd557
migrate New Zealand
tinohager Mar 4, 2024
2ecf429
migrate Singapore
tinohager Mar 4, 2024
35df3b5
cleanup code
tinohager Mar 4, 2024
cc894a0
migrate Russia
tinohager Mar 4, 2024
1ff8713
migrate Venezuela
tinohager Mar 4, 2024
cbb30c0
migrate El Salvador
tinohager Mar 4, 2024
936e49b
migrate Isle of Man
tinohager Mar 4, 2024
fe6667a
migrate Turkey
tinohager Mar 4, 2024
588f574
migrate Switzerland
tinohager Mar 4, 2024
2b44804
optimize naming
tinohager Mar 4, 2024
5a0cfb0
migrate United States of America
tinohager Mar 4, 2024
438ccf6
migrate Germany
tinohager Mar 4, 2024
8469e3d
cleanup code
tinohager Mar 4, 2024
29604b3
optimize religious providers
tinohager Mar 4, 2024
3f0d6d6
optimize console app
tinohager Mar 4, 2024
8986ac6
migrate spain
tinohager Mar 4, 2024
3cf485c
migrate United Kingdom
tinohager Mar 4, 2024
5deb5a1
switch unit tests to observedDate
tinohager Mar 4, 2024
d64ba36
code cleanup
tinohager Mar 4, 2024
fec34de
migrate South Korea
tinohager Mar 4, 2024
59095f5
cleanup code
tinohager Mar 4, 2024
e5b723a
code cleanup
tinohager Mar 4, 2024
a90e016
change naming
tinohager Mar 4, 2024
e848873
cleanup code
tinohager Mar 4, 2024
abd65ad
optimize code
tinohager Mar 4, 2024
6cf70f1
optimize readmes
tinohager Mar 4, 2024
1c11012
optimize readmes
tinohager Mar 4, 2024
3ac6224
Update Nager.Date.csproj
tinohager Mar 4, 2024
7ef729d
fix some small issues
tinohager Mar 5, 2024
5fcfbd0
fix naming
tinohager Mar 5, 2024
b9c951c
move date search logic to helper class
tinohager Mar 5, 2024
1016729
optimize code
tinohager Mar 5, 2024
f7e2b43
update changelog
tinohager Mar 5, 2024
18e5c99
Split DateSystem logic
tinohager Mar 5, 2024
c45bccd
fix build logic
tinohager Mar 5, 2024
8db6994
small fixes
tinohager Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
if: github.event_name != 'pull_request' && github.actor != 'dependabot[bot]'
working-directory: ./src
run: |
sed -i 's/Thank you for supporting open source projects/${{secrets.LICENSE_KEY}}/g' Nager.Date/DateSystem.cs
sed -i 's/Thank you for supporting open source projects/${{secrets.LICENSE_KEY}}/g' Nager.Date/HolidaySystem.cs
sed -i 's/Thank you for supporting open source projects/${{secrets.LICENSE_KEY}}/g' Nager.Date.UnitTest/AssemblyInitialize.cs
- name: Restore dependencies
working-directory: ./src
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.0-alpha] - 2024-03-05

### Added
- Add a second date for holiday observed
### Changed
- Move Day finding logic to DateHelper
- Change project structure
### Removed
- Remove bridge day logic part

## [1.48.0] - 2024-02-12

### Added
Expand Down
47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,51 +181,50 @@ PM> install-package Nager.Date

### Set the license key
```cs
DateSystem.LicenseKey = "LicenseKey1234";
HolidaySystem.LicenseKey = "LicenseKey1234";
```

### Get all publicHolidays of a country and year
### Get all holidays of a country and year
```cs
var publicHolidays = DateSystem.GetPublicHolidays(2021, "DE");
foreach (var publicHoliday in publicHolidays)
var holidays = HolidaySystem.GetHolidays(2024, "DE");
foreach (var holiday in holidays)
{
//publicHoliday...
//publicHoliday.Date -> The date
//publicHoliday.LocalName -> The local name
//publicHoliday.Name -> The english name
//publicHoliday.Fixed -> Is this public holiday every year on the same date
//publicHoliday.Global -> Is this public holiday in every county (federal state)
//publicHoliday.Counties -> Is the public holiday only valid for a special county ISO-3166-2 - Federal states
//publicHoliday.Type -> Public, Bank, School, Authorities, Optional, Observance
//holiday...
//holiday.Date -> The date
//holiday.LocalName -> The local name
//holiday.EnglishName -> The english name
//holiday.NationalHoliday -> Is this public holiday in every county (federal state)
//holiday.SubdivisionCodes -> Is the public holiday only valid for a special county ISO-3166-2 - Federal states
//holiday.HolidayTypes -> Public, Bank, School, Authorities, Optional, Observance
}
```

### Get all publicHolidays for a date range
### Get all holidays for a date range
```cs
var startDate = new DateTime(2016, 5, 1);
var endDate = new DateTime(2021, 5, 31);
var publicHolidays = DateSystem.GetPublicHolidays(startDate, endDate, CountryCode.DE);
foreach (var publicHoliday in publicHolidays)
var endDate = new DateTime(2024, 5, 31);
var holidays = HolidaySystem.GetHolidays(startDate, endDate, CountryCode.DE);
foreach (var holiday in holidays)
{
//publicHoliday...
//holiday...
}
```

### Check if a date is a public holiday
```cs
var date = new DateTime(2021, 1, 1);
if (DateSystem.IsPublicHoliday(date, CountryCode.DE))
var date = new DateTime(2024, 1, 1);
if (HolidaySystem.IsPublicHoliday(date, CountryCode.DE))
{
Console.WriteLine("Is public holiday");
Console.WriteLine("Is a public holiday");
}
```

### Check if a date is a weekend day
### Checks if the given date falls on a weekend day
```cs
var date = new DateTime(2021, 1, 1);
if (DateSystem.IsWeekend(date, CountryCode.DE))
var date = new DateTime(2024, 1, 1);
if (WeekendSystem.IsWeekend(date, CountryCode.DE))
{
Console.WriteLine("Is weekend");
Console.WriteLine("The date is in the weekend");
}
```
</details>
Expand Down
45 changes: 22 additions & 23 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nager.Date

Nager.Date is a popular project to query holidays. We currently support over 100 countries.
Nager.Date is a popular project for querying holidays, we currently support for over 100 countries.

## Country Support
The list of supported countries can be found [here](https://date.nager.at/Country/Coverage)
Expand All @@ -9,45 +9,44 @@ The list of supported countries can be found [here](https://date.nager.at/Countr

### Get all publicHolidays of a country and year
```cs
var publicHolidays = DateSystem.GetPublicHolidays(2021, "DE");
foreach (var publicHoliday in publicHolidays)
var holidays = HolidaySystem.GetHolidays(2024, "DE");
foreach (var holiday in holidays)
{
//publicHoliday...
//publicHoliday.Date -> The date
//publicHoliday.LocalName -> The local name
//publicHoliday.Name -> The english name
//publicHoliday.Fixed -> Is this public holiday every year on the same date
//publicHoliday.Global -> Is this public holiday in every county (federal state)
//publicHoliday.Counties -> Is the public holiday only valid for a special county ISO-3166-2 - Federal states
//publicHoliday.Type -> Public, Bank, School, Authorities, Optional, Observance
//holiday...
//holiday.Date -> The date
//holiday.LocalName -> The local name
//holiday.EnglishName -> The english name
//holiday.NationalHoliday -> Is this holiday in every county (federal state)
//holiday.SubdivisionCodes -> Is the public holiday only valid for a special county ISO-3166-2 - Federal states
//holiday.HolidayTypes -> Public, Bank, School, Authorities, Optional, Observance
}
```

### Get all publicHolidays for a date range
### Get all holidays for a date range
```cs
var startDate = new DateTime(2016, 5, 1);
var endDate = new DateTime(2021, 5, 31);
var publicHolidays = DateSystem.GetPublicHolidays(startDate, endDate, CountryCode.DE);
foreach (var publicHoliday in publicHolidays)
var endDate = new DateTime(2024, 5, 31);
var holidays = HolidaySystem.GetHolidays(startDate, endDate, CountryCode.DE);
foreach (var holiday in holidays)
{
//publicHoliday...
//holiday...
}
```

### Check if a date is a public holiday
```cs
var date = new DateTime(2021, 1, 1);
if (DateSystem.IsPublicHoliday(date, CountryCode.DE))
var date = new DateTime(2024, 1, 1);
if (HolidaySystem.IsPublicHoliday(date, CountryCode.DE))
{
Console.WriteLine("Is public holiday");
Console.WriteLine("Is a public holiday");
}
```

### Check if a date is a weekend day
### Checks if the given date falls on a weekend day
```cs
var date = new DateTime(2021, 1, 1);
if (DateSystem.IsWeekend(date, CountryCode.DE))
var date = new DateTime(2024, 1, 1);
if (WeekendSystem.IsWeekend(date, CountryCode.DE))
{
Console.WriteLine("Is weekend");
Console.WriteLine("The date is in the weekend");
}
```
11 changes: 6 additions & 5 deletions src/Nager.Date.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Nager.Date;

DateSystem.LicenseKey = "Thank you for supporting open source projects";
HolidaySystem.LicenseKey = "Thank you for supporting open source projects";

Console.WriteLine("Nager.Date");

Expand All @@ -19,11 +19,12 @@
}

Console.WriteLine($"Calculate holidays for {countryCode.ToUpper()} {year}");
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("--------------------------------------------------------------------------------------------------");
Console.WriteLine("Date Observed English Name Local Name Type");

var publicHolidays = DateSystem.GetPublicHolidays(year, countryCode);
var publicHolidays = HolidaySystem.GetHolidays(year, countryCode);
foreach (var publicHoliday in publicHolidays)
{
var counties = publicHoliday.Counties != null ? string.Join(',', publicHoliday.Counties) : "";
Console.WriteLine($"{publicHoliday.Date:d}{"",3}{publicHoliday.Name,30}{"",3}{publicHoliday.LocalName,30}{"",3}{publicHoliday.Type}{"",3}{counties}");
var counties = publicHoliday.SubdivisionCodes != null ? string.Join(',', publicHoliday.SubdivisionCodes) : "";
Console.WriteLine($"{publicHoliday.Date:d}{"",3}{publicHoliday.ObservedDate:d}{"",3}{publicHoliday.EnglishName,30}{"",3}{publicHoliday.LocalName,30}{"",3}{publicHoliday.HolidayTypes}{"",3}{counties}");
}
2 changes: 1 addition & 1 deletion src/Nager.Date.UnitTest/AssemblyInitialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class AssemblyInitialize
[AssemblyInitialize]
public static void MyTestInitialize(TestContext testContext)
{
DateSystem.LicenseKey = "Thank you for supporting open source projects";
HolidaySystem.LicenseKey = "Thank you for supporting open source projects";
}
}
}
24 changes: 12 additions & 12 deletions src/Nager.Date.UnitTest/Common/CountryTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nager.Date.Contract;
using Nager.Date.HolidayProviders;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -14,7 +14,7 @@ public void CheckCountries()
{
foreach (CountryCode countryCode in Enum.GetValues(typeof(CountryCode)))
{
var provider = DateSystem.GetPublicHolidayProvider(countryCode);
var provider = HolidaySystem.GetHolidayProvider(countryCode);

var publicHolidays = provider.GetHolidays(2018);
if (!publicHolidays.Any())
Expand All @@ -36,28 +36,28 @@ public void CheckCounties()

foreach (CountryCode countryCode in Enum.GetValues(typeof(CountryCode)))
{
var provider = DateSystem.GetPublicHolidayProvider(countryCode);
var counties = provider is ICountyProvider countyProvider
? countyProvider.GetCounties()
var provider = HolidaySystem.GetHolidayProvider(countryCode);
var subdivisionCodes = provider is ISubdivisionCodesProvider subdivisionCodesProvider
? subdivisionCodesProvider.GetSubdivisionCodes()
: new Dictionary<string, string>();

var startYear = DateTime.Today.Year - 100;
var endYear = DateTime.Today.Year + 100;

for (var year = startYear; year <= endYear; year++)
{
var publicHolidays = DateSystem.GetPublicHolidays(year, countryCode);
var publicHolidays = HolidaySystem.GetHolidays(year, countryCode);
foreach (var publicHoliday in publicHolidays)
{
if (publicHoliday.Counties == null)
if (publicHoliday.SubdivisionCodes == null)
{
continue;
}

if (publicHoliday.Counties.Count(o => counties.Keys.Contains(o)) != publicHoliday.Counties.Length)
if (publicHoliday.SubdivisionCodes.Count(o => subdivisionCodes.Keys.Contains(o)) != publicHoliday.SubdivisionCodes.Length)
{
var diff = publicHoliday.Counties.Except(counties.Keys);
failures.Add($"Unknown county in {provider} \"{publicHoliday.Name}\" {string.Join(',', diff)}");
var diff = publicHoliday.SubdivisionCodes.Except(subdivisionCodes.Keys);
failures.Add($"Unknown subdivisionCode in {provider} \"{publicHoliday.EnglishName}\" {string.Join(',', diff)}");
}
}
}
Expand All @@ -77,15 +77,15 @@ public void CheckCounties()
[DataRow("DE")]
public void CheckCaseInsensitive(string countryCode)
{
var result = DateSystem.GetPublicHolidays(2018, countryCode);
var result = HolidaySystem.GetHolidays(2018, countryCode);

Assert.IsNotNull(result);
}

[TestMethod]
public void ThrowOnUndefinedEnum()
{
Assert.ThrowsException<ArgumentException>(() => DateSystem.GetPublicHolidays(2018, "1000"));
Assert.ThrowsException<ArgumentException>(() => HolidaySystem.GetHolidays(2018, "1000"));
}
}
}
Loading