├── .github
├── FUNDING.yml
└── workflows
│ └── dotnet.yml
├── BrazilHolidays.Net
├── Interfaces
│ └── IHoliday.cs
├── Enums
│ ├── Months.cs
│ └── HolidayIdentity.cs
├── Models
│ ├── Today.cs
│ ├── Yesterday.cs
│ ├── Tomorrow.cs
│ └── Holiday.cs
├── Extensions
│ └── HolidayExtention.cs
└── BrazilHolidays.Net.csproj
├── UnitTest
├── CustomHolidayTests.cs
├── UnitTest.csproj
├── WillHappenInTest.cs
├── ToLeapYearMoving.cs
├── ToNotLeapYearMoving.cs
├── OutherTests.cs
└── ToCurrentYearTest.cs
├── LICENSE
├── README.md
├── BrazilHolidays.Net.sln
├── .gitattributes
└── .gitignore
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: alexandresanlim
4 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net/Interfaces/IHoliday.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BrazilHolidays.Net
4 | {
5 | public interface IHoliday
6 | {
7 | string Title { get; }
8 |
9 | DateTime Date { get; }
10 |
11 | HolidayIdentity Identity { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net/Enums/Months.cs:
--------------------------------------------------------------------------------
1 | namespace BrazilHolidays.Net
2 | {
3 | public enum Months
4 | {
5 | Jan = 1,
6 | Feb,
7 | Mar,
8 | Apr,
9 | May,
10 | Jun,
11 | Jul,
12 | Aug,
13 | Sep,
14 | Oct,
15 | Nov,
16 | Dec
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net/Models/Today.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BrazilHolidays.Net
4 | {
5 | public static class Today
6 | {
7 | public static bool IsHoliday()
8 | {
9 | return DateTime.Today.IsHoliday();
10 | }
11 |
12 | public static bool IsNotHoliday()
13 | {
14 | return !IsHoliday();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net/Models/Yesterday.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BrazilHolidays.Net
4 | {
5 | public static class Yesterday
6 | {
7 | public static bool WasHoliday()
8 | {
9 | return DateTime.Today.AddDays(-1).IsHoliday();
10 | }
11 |
12 | public static bool WasNotHoliday()
13 | {
14 | return !WasHoliday();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net/Models/Tomorrow.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BrazilHolidays.Net
4 | {
5 | public static class Tomorrow
6 | {
7 | public static bool WillBeHoliday()
8 | {
9 | return DateTime.Today.AddDays(1).IsHoliday();
10 | }
11 |
12 | public static bool WilNotBeHoliday()
13 | {
14 | return !WillBeHoliday();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net/Enums/HolidayIdentity.cs:
--------------------------------------------------------------------------------
1 | namespace BrazilHolidays.Net
2 | {
3 | public enum HolidayIdentity
4 | {
5 | Custom = -1,
6 | AnoNovo,
7 | Tiradentes,
8 | DiaDoTrabalho,
9 | IdependenciaDoBrasil,
10 | NossaSenhoraAparecida,
11 | Finados,
12 | ProclamacaoDaRepublica,
13 | Natal,
14 | Pascoa,
15 | SextaFeiraSanta,
16 | Carnaval,
17 | CorpusChristi,
18 | ConscienciaNegra
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/UnitTest/CustomHolidayTests.cs:
--------------------------------------------------------------------------------
1 | using BrazilHolidays.Net;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using System;
4 |
5 | namespace UnitTest
6 | {
7 | [TestClass]
8 | public class CustomHolidayTests
9 | {
10 | [TestMethod]
11 | public void AddCustom()
12 | {
13 | var custom = new Holiday(DateTime.Today, "Teste");
14 | Holiday.AddCustomHoliday(custom);
15 |
16 | var list = Holiday.GetAllByYear();
17 |
18 | Assert.IsTrue(Today.IsHoliday());
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/UnitTest/UnitTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.github/workflows/dotnet.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a .NET project
2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3 |
4 | name: .NET
5 |
6 | on:
7 | push:
8 | branches: [ "master" ]
9 | pull_request:
10 | branches: [ "master" ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v3
19 | - name: Setup .NET
20 | uses: actions/setup-dotnet@v3
21 | with:
22 | dotnet-version: 3.1.x
23 | - name: Restore dependencies
24 | run: dotnet restore
25 | - name: Build
26 | run: dotnet build --no-restore
27 | - name: Test
28 | run: dotnet test --no-build --verbosity normal
29 |
--------------------------------------------------------------------------------
/UnitTest/WillHappenInTest.cs:
--------------------------------------------------------------------------------
1 | using BrazilHolidays.Net;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using System;
4 |
5 | namespace UnitTest
6 | {
7 | [TestClass]
8 | public class WillHappenInTest
9 | {
10 | [TestMethod]
11 | public void WillHappenNatal()
12 | {
13 | var natal = Holiday.GetOneByYear(HolidayIdentity.Natal, DateTime.Now.Year);
14 | var daysToNatal = natal.HappenInDays();
15 | }
16 |
17 | [TestMethod]
18 | public void WillHappenDiaDoTrabalho()
19 | {
20 | var diaDoTrabalho = Holiday.GetOneByYear(HolidayIdentity.DiaDoTrabalho, DateTime.Now.Year);
21 | var daysToDiaDoTrabalho = diaDoTrabalho.HappenInDays();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/UnitTest/ToLeapYearMoving.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 | using BrazilHolidays.Net;
6 |
7 | namespace UnitTest
8 | {
9 | [TestClass]
10 | public class ToLeapYearMoving
11 | {
12 | public int LeapYear => 2020;
13 |
14 | [TestMethod]
15 | public void Pascoa()
16 | {
17 | Assert.IsTrue(new DateTime(LeapYear, 4, 12).IsHoliday());
18 | }
19 |
20 | [TestMethod]
21 | public void SextaFeiraSanta()
22 | {
23 | Assert.IsTrue(new DateTime(LeapYear, 4, 10).IsHoliday());
24 | }
25 |
26 | [TestMethod]
27 | public void Carnaval()
28 | {
29 | Assert.IsTrue(new DateTime(LeapYear, 2, 25).IsHoliday());
30 | }
31 |
32 | [TestMethod]
33 | public void CorpusChristi()
34 | {
35 | Assert.IsTrue(new DateTime(LeapYear, 6, 11).IsHoliday());
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/UnitTest/ToNotLeapYearMoving.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 | using BrazilHolidays.Net;
6 |
7 | namespace UnitTest
8 | {
9 | [TestClass]
10 | public class ToNotLeapYearMoving
11 | {
12 | public int LeapYear => 2021;
13 |
14 | [TestMethod]
15 | public void Pascoa()
16 | {
17 | Assert.IsTrue(new DateTime(LeapYear, 4, 4).IsHoliday());
18 | }
19 |
20 | [TestMethod]
21 | public void SextaFeiraSanta()
22 | {
23 | Assert.IsTrue(new DateTime(LeapYear, 4, 2).IsHoliday());
24 | }
25 |
26 | [TestMethod]
27 | public void Carnaval()
28 | {
29 | Assert.IsTrue(new DateTime(LeapYear, 2, 16).IsHoliday());
30 | }
31 |
32 | [TestMethod]
33 | public void CorpusChristi()
34 | {
35 | Assert.IsTrue(new DateTime(LeapYear, 6, 3).IsHoliday());
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Alexandre Sanlim
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net/Extensions/HolidayExtention.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 |
4 | namespace BrazilHolidays.Net
5 | {
6 | public static class HolidayExtention
7 | {
8 | public static bool IsHoliday(this DateTime dateToTest)
9 | {
10 | return Holiday.GetAllByYear(dateToTest.Year).Any(x => x.Date.Date.Equals(dateToTest.Date));
11 | }
12 |
13 | public static TimeSpan HappenInTime(this IHoliday holiday)
14 | {
15 | return (holiday.Date - DateTime.Now.Date);
16 | }
17 |
18 | public static int HappenInDays(this IHoliday holiday)
19 | {
20 | return HappenInTime(holiday).Days;
21 | }
22 |
23 | public static int HappenHours(this IHoliday holiday)
24 | {
25 | return HappenInTime(holiday).Hours;
26 | }
27 |
28 | public static int HappenAtMinutes(this IHoliday holiday)
29 | {
30 | return HappenInTime(holiday).Minutes;
31 | }
32 |
33 | public static int HappenAtSeconds(this IHoliday holiday)
34 | {
35 | return HappenInTime(holiday).Seconds;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/UnitTest/OutherTests.cs:
--------------------------------------------------------------------------------
1 | using BrazilHolidays.Net;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using System;
4 |
5 | namespace UnitTest
6 | {
7 | [TestClass]
8 | public class OutherTests
9 | {
10 | [TestMethod]
11 | public void TodayIsHoliday()
12 | {
13 | var isHoliday = Today.IsHoliday();
14 | Assert.IsNotNull(isHoliday);
15 | }
16 |
17 | [TestMethod]
18 | public void TodayIsNotHoliday()
19 | {
20 | var isNotHoliday = Today.IsNotHoliday();
21 | Assert.IsNotNull(isNotHoliday);
22 | }
23 |
24 | [TestMethod]
25 | public void GetAllNext()
26 | {
27 | var list = Holiday.GetAllNext();
28 | Assert.IsNotNull(list);
29 | }
30 |
31 | [TestMethod]
32 | public void GetOld()
33 | {
34 | var list = Holiday.GetOld();
35 | Assert.IsNotNull(list);
36 | }
37 |
38 | [TestMethod]
39 | public void GetNext()
40 | {
41 | var list = Holiday.GetNext();
42 | Assert.IsNotNull(list);
43 | }
44 |
45 | [TestMethod]
46 | public void GetAllByMonth()
47 | {
48 | var list = Holiday.GetAllByMonth(Months.Dec);
49 | Assert.IsNotNull(list);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net/BrazilHolidays.Net.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net45;netstandard1.4;netstandard1.6;netstandard2.0;net7.0;net8.0
5 | Alexandre Sanlim
6 | https://github.com/alexandresanlim/BrazilHolidays.Net
7 | https://github.com/alexandresanlim/BrazilHolidays.Net
8 | Brazil;Brasil;Holiday,Holidays,Feriados,Feriado
9 | Teste se uma data especifia ou se a data atual é um feriado, incluindo feriados móveis como Páscoa, Sexta-Feira Santa, e etc... Suporte a ano bisexto
10 | 1.0.4
11 | README.md
12 | LICENSE
13 | - Adicionado dia da consciência negra
14 | - Adicionado suporte para o .net8
15 | - Melhorias de performance
16 | Brazil Holidays - Feriados no Brasil
17 |
18 |
19 |
20 |
21 | True
22 | \
23 |
24 |
25 | True
26 | \
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BrazilHolidays.Net
2 | [](https://www.nuget.org/packages/BrazilHolidays.Net)
3 | [](https://www.nuget.org/packages/BrazilHolidays.Net)
4 |
5 | Instale [este pacote](https://www.nuget.org/packages/BrazilHolidays.Net) via nuget ou linha de comando:
6 | ```nuget
7 | Install-Package BrazilHolidays.Net
8 | ```
9 |
10 | ## Como usar
11 |
12 | - Hoje é feriado? (Is today a holiday?)
13 | ```csharp
14 | BrazilHolidays.Net.Today.IsHoliday();
15 | ```
16 |
17 | - Uma data especifica é feriado? (Is a specific date a holiday?)
18 | ```csharp
19 | new DateTime(2020, 12, 25).IsHoliday()
20 | ```
21 |
22 | - Lista dos próximos feriados (Get a list of next holidays)
23 | ```csharp
24 | BrazilHolidays.Net.Holiday.GetAllNext();
25 | ```
26 |
27 | - Pegar o ultimo (Get the last holiday)
28 | ```csharp
29 | BrazilHolidays.Net.Holiday.GetOld();
30 | ```
31 |
32 | - Pegar o próximo (Get the next holiday)
33 | ```csharp
34 | BrazilHolidays.Net.Holiday.GetNext();
35 | ```
36 |
37 | - Pegar todos de um determinado mês (Get a list by month)
38 | ```csharp
39 | BrazilHolidays.Net.Holiday.GetAllByMonth(BrazilHolidays.Net.DataStore.Holiday.Months.Dec);
40 | ```
41 |
42 | ### Este projeto incluí testes:
43 | - Feriados para o ano corrente
44 | - Feriados para datas móveis em um ano bissexto e não bissexto.
45 | - Se a data atual é feriado
46 |
47 | 
48 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30611.23
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrazilHolidays.Net", "BrazilHolidays.Net\BrazilHolidays.Net.csproj", "{EC0F16C2-1749-43B8-8290-5CDD7101501C}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest", "UnitTest\UnitTest.csproj", "{2E6EF694-B946-4402-B4E6-C1F1C8C95B93}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {EC0F16C2-1749-43B8-8290-5CDD7101501C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {EC0F16C2-1749-43B8-8290-5CDD7101501C}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {EC0F16C2-1749-43B8-8290-5CDD7101501C}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {EC0F16C2-1749-43B8-8290-5CDD7101501C}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {2E6EF694-B946-4402-B4E6-C1F1C8C95B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {2E6EF694-B946-4402-B4E6-C1F1C8C95B93}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {2E6EF694-B946-4402-B4E6-C1F1C8C95B93}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {2E6EF694-B946-4402-B4E6-C1F1C8C95B93}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {1171D789-086E-47E9-9DE7-F7A580302973}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/UnitTest/ToCurrentYearTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using BrazilHolidays.Net;
4 |
5 | namespace UnitTest
6 | {
7 | [TestClass]
8 | public class ToCurrentYearTest
9 | {
10 | public int Year => DateTime.Now.Year;
11 |
12 | [TestMethod]
13 | public void AnoNovo()
14 | {
15 | Assert.IsTrue(new DateTime(Year, 1, 1).IsHoliday());
16 | }
17 |
18 | [TestMethod]
19 | public void Tiradentes()
20 | {
21 | Assert.IsTrue(new DateTime(Year, 4, 21).IsHoliday());
22 | }
23 |
24 | [TestMethod]
25 | public void DiaDoTrabalho()
26 | {
27 | Assert.IsTrue(new DateTime(Year, 5, 1).IsHoliday());
28 | }
29 |
30 | [TestMethod]
31 | public void Independencia()
32 | {
33 | Assert.IsTrue(new DateTime(Year, 9, 7).IsHoliday());
34 | }
35 |
36 | [TestMethod]
37 | public void NossaSenhoraAparecida()
38 | {
39 | Assert.IsTrue(new DateTime(Year, 10, 12).IsHoliday());
40 | }
41 |
42 | [TestMethod]
43 | public void Finados()
44 | {
45 | Assert.IsTrue(new DateTime(Year, 11, 2).IsHoliday());
46 | }
47 |
48 | [TestMethod]
49 | public void ProclamacaoDaRepublica()
50 | {
51 | Assert.IsTrue(new DateTime(Year, 11, 15).IsHoliday());
52 | }
53 |
54 | [TestMethod]
55 | public void ConscienciaNegra()
56 | {
57 | Assert.IsTrue(new DateTime(Year, 11, 20).IsHoliday());
58 | }
59 |
60 | [TestMethod]
61 | public void Natal()
62 | {
63 | Assert.IsTrue(new DateTime(Year, 12, 25).IsHoliday());
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/BrazilHolidays.Net/Models/Holiday.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace BrazilHolidays.Net
6 | {
7 | public class Holiday : IHoliday
8 | {
9 | public Holiday(DateTime _dateTime, string _title)
10 | {
11 | Title = _title;
12 | Date = _dateTime;
13 | }
14 |
15 | public string Title { get; private set; }
16 |
17 | public DateTime Date { get; private set; }
18 |
19 | public HolidayIdentity Identity { get; set; }
20 |
21 | private static List CustomHolidayList { get; set; } = new List();
22 |
23 | public static void AddCustomHoliday(IHoliday holidayToAddInCustom)
24 | {
25 | holidayToAddInCustom.Identity = HolidayIdentity.Custom;
26 | CustomHolidayList.Add(holidayToAddInCustom);
27 | }
28 |
29 | public static void AddCustomHoliday(IEnumerable holidayToAddInCustomList)
30 | {
31 | CustomHolidayList.AddRange(holidayToAddInCustomList);
32 | }
33 |
34 | public static IEnumerable GetAllByMonth(Months month)
35 | {
36 | return GetAllNext().Where(x => x.Date.Month == (int)month);
37 | }
38 |
39 | public static IHoliday GetNext()
40 | {
41 | return GetAllNext().FirstOrDefault();
42 | }
43 |
44 | public static IHoliday GetOld()
45 | {
46 | return GetAllByYear(DateTime.Today.Year).LastOrDefault(x => x.Date <= DateTime.Today);
47 | }
48 |
49 | public static IEnumerable GetAllNext()
50 | {
51 | var actualMonth = DateTime.Today.Month;
52 |
53 | var nextActualYear = GetAllByYear(DateTime.Today.Year).Where(x => x.Date.Month >= actualMonth && x.Date >= DateTime.Today.Date);
54 | var nextNextYear = GetAllByYear(DateTime.Today.Year + 1).Where(x => x.Date.Month <= actualMonth);
55 |
56 | var l = new List();
57 | l.AddRange(nextActualYear);
58 | l.AddRange(nextNextYear);
59 |
60 | return l.OrderBy(x => x.Date);
61 | }
62 |
63 | /// Ano para buscar os feriados, por padrão é o ano corrente
64 | /// Lista de todos feriados, fixos, móveis e customizados
65 | public static IEnumerable GetAllByYear(int? yearParameter = null)
66 | {
67 | var holidayList = new List();
68 |
69 | var year = yearParameter ?? DateTime.Today.Year;
70 |
71 | holidayList.AddRange(GetAllFixByYear(year));
72 | holidayList.AddRange(GetAllMoveByYear(year));
73 | holidayList.AddRange(CustomHolidayList);
74 |
75 | return holidayList.OrderBy(z => z.Date);
76 | }
77 |
78 | /// Ano para buscar os feriados, por padrão é o ano corrente
79 | /// Lista de feriados fixos como Natal
80 | public static IEnumerable GetAllFixByYear(int? yearParameter = null)
81 | {
82 | var year = yearParameter ?? DateTime.Today.Year;
83 |
84 | var holidayList = new List
85 | {
86 | new Holiday(new DateTime(year, 1, 1), "Ano Novo") { Identity = HolidayIdentity.AnoNovo },
87 | new Holiday(new DateTime(year, 4, 21), "Tiradentes") { Identity = HolidayIdentity.Tiradentes },
88 | new Holiday(new DateTime(year, 5, 1), "Dia do trabalho") { Identity = HolidayIdentity.DiaDoTrabalho },
89 | new Holiday(new DateTime(year, 9, 7), "Independência do Brasil") { Identity = HolidayIdentity.IdependenciaDoBrasil },
90 | new Holiday(new DateTime(year, 10, 12), "Nossa Senhora Aparecida") { Identity = HolidayIdentity.NossaSenhoraAparecida },
91 | new Holiday(new DateTime(year, 11, 2), "Finados") { Identity = HolidayIdentity.Finados },
92 | new Holiday(new DateTime(year, 11, 15), "Proclamação da República") { Identity = HolidayIdentity.ProclamacaoDaRepublica },
93 | new Holiday(new DateTime(year, 11, 20), "Consciência Negra") { Identity = HolidayIdentity.ConscienciaNegra },
94 | new Holiday(new DateTime(year, 12, 25), "Natal") { Identity = HolidayIdentity.Natal }
95 | };
96 |
97 | return holidayList;
98 |
99 | }
100 |
101 | /// Ano para buscar os feriados, por padrão é o ano corrente
102 | /// Lista de feriados móveis
103 | public static IEnumerable GetAllMoveByYear(int? yearParameter = null)
104 | {
105 | var holidayList = new List();
106 |
107 | var year = yearParameter ?? DateTime.Today.Year;
108 |
109 | #region FeriadosMóveis
110 |
111 | int x, y;
112 | int a, b, c, d, e;
113 | int day, month;
114 |
115 | if (year >= 1900 & year <= 2099)
116 | {
117 | x = 24;
118 | y = 5;
119 | }
120 | else
121 | if (year >= 2100 & year <= 2199)
122 | {
123 | x = 24;
124 | y = 6;
125 | }
126 | else
127 | if (year >= 2200 & year <= 2299)
128 | {
129 | x = 25;
130 | y = 7;
131 | }
132 | else
133 | {
134 | x = 24;
135 | y = 5;
136 | }
137 |
138 | a = year % 19;
139 | b = year % 4;
140 | c = year % 7;
141 | d = (19 * a + x) % 30;
142 | e = (2 * b + 4 * c + 6 * d + y) % 7;
143 |
144 | if ((d + e) > 9)
145 | {
146 | day = (d + e - 9);
147 | month = 4;
148 | }
149 |
150 | else
151 | {
152 | day = (d + e + 22);
153 | month = 3;
154 | }
155 |
156 | var pascoa = new DateTime(year, month, day);
157 | var sextaSanta = pascoa.AddDays(-2);
158 | var carnaval = pascoa.AddDays(-47);
159 | var corpusChristi = pascoa.AddDays(60);
160 |
161 | holidayList.Add(new Holiday(pascoa, "Páscoa") { Identity = HolidayIdentity.Pascoa });
162 | holidayList.Add(new Holiday(sextaSanta, "Sexta-Feira Santa") { Identity = HolidayIdentity.SextaFeiraSanta });
163 | holidayList.Add(new Holiday(carnaval, "Carnaval") { Identity = HolidayIdentity.Carnaval });
164 | holidayList.Add(new Holiday(corpusChristi, "Corpus Christi") { Identity = HolidayIdentity.CorpusChristi });
165 |
166 | #endregion
167 |
168 | return holidayList;
169 | }
170 |
171 | /// Lista de feriados customizaveis que não são feriados nacionais mas foram adicionados usando o método AddCustomHoliday
172 | public static IEnumerable GetAllCustomByYear() => CustomHolidayList;
173 |
174 | public static IHoliday GetOneByYear(HolidayIdentity identity, int? yearParameter = null)
175 | {
176 | return GetAllByYear(yearParameter).FirstOrDefault(x => x.Identity == identity);
177 | }
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------