• Stars
    star
    1,080
  • Rank 42,517 (Top 0.9 %)
  • Language
    C#
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Worldwide holidays (REST API), NuGet or docker container 🌎

Build status

πŸ“† Nager.Date - Official Website

Discover the convenience of easily accessing holidays from over 100 countries with Nager.Date. Our popular project utilizes the power of .NET and offers a user-friendly public REST API for seamless integration into your application.

You can find an overview of the supported countries here.

Need offline access to our functionality? No problem! We also provide solutions that allow you to use our services on your own infrastructure without an internet connection. Easily integrate our service into your system with the Docker container or the NuGet package. Both options require a license key. As a sponsor of nager, you get a license key.

How can I use it?

Easily create a client in your preferred programming language by utilizing our Swagger definition. Find all the necessary information in our API section. Get more details about client generation in the documentation.

Examples

.NET/C# (click to expand)

There are two ways to use our service

NuGet - Nager.Holiday

PM> install-package Nager.Holiday

Copy Code

using System;
using System.Net.Http;
using System.Text.Json;

var jsonSerializerOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };

using var httpClient = new HttpClient();
using var response = await httpClient.GetAsync("https://date.nager.at/api/v3/publicholidays/2022/US");
if (response.IsSuccessStatusCode)
{
    using var jsonStream = await response.Content.ReadAsStreamAsync();
    var publicHolidays = JsonSerializer.Deserialize<PublicHoliday[]>(jsonStream, jsonSerializerOptions);
}

class PublicHoliday
{
    public DateTime Date { get; set; }
    public string LocalName { get; set; }
    public string Name { get; set; }
    public string CountryCode { get; set; }
    public bool Fixed { get; set; }
    public bool Global { get; set; }
    public string[] Counties { get; set; }
    public int? LaunchYear { get; set; }
    public string[] Types { get; set; }
}
PHP (click to expand)

This example use the guzzle project

<?php
require_once 'vendor/autoload.php';
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://date.nager.at/api/v3/publicholidays/2022/US');
if ($response->getStatusCode() == 200) {
    $json = $response->getBody();
    print_r(json_decode($json));
}
?>
Java (click to expand)

This example use the springframework. Code tested with onecompiler.com

Main.java

import java.util.*;
import org.springframework.web.client.RestTemplate;
import com.google.gson.*;

public class Main {
  public static void main(String[] args) {
    System.out.println("get holidays");
    String json = new RestTemplate().getForObject("https://date.nager.at/api/v3/publicholidays/2022/CH", String.class);
    
    Gson gson = new Gson();
    PublicHoliday[] userArray = gson.fromJson(json, PublicHoliday[].class);  

    for(PublicHoliday publicHoliday : userArray) {
      System.out.print(publicHoliday.date);
      System.out.print(" ");
      System.out.print(publicHoliday.name);
      System.out.print(" ");
      System.out.print(String.join(",", publicHoliday.counties ?? new String[0]));
      System.out.print(" ");
      System.out.println(publicHoliday.localName);
    }
  }
}

PublicHoliday.java

public class PublicHoliday {
  public String date;
  public String localName;
  public String name;
  public String countryCode ;
  public Boolean fixed;
  public Boolean global;
  public String[] counties;
  public String[] types;
}

build.gradle

apply plugin:'application'
mainClassName = 'Main'

run { standardInput = System.in }
sourceSets { main { java { srcDir './' } } }

repositories {
  jcenter()
}

dependencies {
  implementation 'org.springframework.boot:spring-boot-starter-web:2.6.7';
  implementation 'com.google.code.gson:gson:2.10.1';
}
Python (click to expand)

main.py

import json
import requests

response = requests.get('https://date.nager.at/api/v3/publicholidays/2022/US')
public_holidays = json.loads(response.content)

for public_holiday in public_holidays:
  print(public_holiday['date'])

Offline Solution

Don't let internet connectivity issues disrupt your workflow. Our offline solutions enable you to use our services on your own infrastructure without an internet connection. With a sponsorship you get the license key to use the variants locally without a dependency to our REST API.

NuGet

The NuGet package is available via NuGet

PM> install-package Nager.Date
Code Examples (click to expand)

Examples for .NET (NuGet package)

Set the license key

DateSystem.LicenseKey = "LicenseKey1234";

Get all publicHolidays of a country and year

var publicHolidays = DateSystem.GetPublicHolidays(2021, "DE");
foreach (var publicHoliday in publicHolidays)
{
    //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
}

Get all publicHolidays for a date range

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)
{
	//publicHoliday...
}

Check if a date is a public holiday

var date = new DateTime(2021, 1, 1);
if (DateSystem.IsPublicHoliday(date, CountryCode.DE))
{
    Console.WriteLine("Is public holiday");
}

Check if a date is a weekend day

var date = new DateTime(2021, 1, 1);
if (DateSystem.IsWeekend(date, CountryCode.DE))
{
    Console.WriteLine("Is weekend");
}

Docker

The Docker container is available via Docker Hub
To run a local instance of the Docker image run the following command
docker run -p 80:80 nager/nager-date

Holiday types

What variants of holidays are supported by Nager.Date

Type Description
Public Public holiday
Bank Bank holiday, banks and offices are closed
School School holiday, schools are closed
Authorities Authorities are closed
Optional Majority of people take a day off
Observance Optional festivity, no paid day off

Areas of Application

There are several business fields in which it is important to know the holidays in different countries.

  • E-commerce: If an online retailer sells its products in different countries, it should know the holidays in these countries to adjust delivery times and customer service accordingly.
  • Travel industry: A tour operator should know the holidays of the countries to which it offers trips, to alert its customers to special events or closed attractions.
  • Staff scheduling: Companies with branches in several countries must know the holidays in each country to be able to plan their staff needs accordingly.
  • Financial industry: Banks and financial institutions should know the holidays in the countries in which they conduct business to ensure that transfers and transactions are performed on time and to estimate the impact of holidays on the foreign exchange market.
  • Logistics and supply chains: Companies managing logistics or supply chains across several countries, must know the holidays in these countries to adjust planning and supply chain decisions.
  • Telephone systems: To automatically turn on the answering machine on holidays.
  • Time recording: To automatically fill the missing hours with the normal working hours.

Articles about this project

More Repositories

1

Nager.AmazonProductAdvertising

.NET Amazon Product Advertising Client
C#
157
star
2

Nager.PublicSuffix

.NET public suffix domain parser
C#
152
star
3

Nager.Country

Worldwide Country Informations (ISO-3166-1 Alpha2, ISO-3166-1 Alpha3, ISO 639-1)
C#
111
star
4

Nager.VideoStream

Get images from a network camera stream or webcam
C#
47
star
5

Nager.ArticleNumber

C# Validate Article Numbers ASIN, EAN8, EAN13, GTIN, ISBN, ISBN13, SKU, UPC
C#
31
star
6

Nager.TcpClient

A simple asynchronous TcpClient
C#
15
star
7

Nager.TemplateBuilder

Visual Studio Solution Builder
C#
10
star
8

Nager.FirewallManagement

Manage the default Windows Firewall over an WebAPI
C#
5
star
9

Nager.Holiday

Holiday Client for date.nager.at
C#
4
star
10

Nager.UdpDeviceDiscovery

Udp Broadcast device discovery
C#
3
star
11

Nager.TextValidation

Validate text via keyboard keys position
C#
2
star
12

Nager.CertificateManagement

Certificates management for Lets Encrypt
C#
2
star
13

Nager.ArduinoStepperMotor

.NET control a stepper motor via arduino
C++
2
star
14

Nager.AmazonSesNotification

Amazon Simple Email Service Notification Processing
C#
2
star
15

Nager.WindowsCalendarWeek

Show CalendarWeek in SystemTray of Microsoft Windows
C#
2
star
16

Nager.DataFragmentationHandler

Process fragmented bytes via a buffer to packages
C#
1
star
17

Nager.ConfigParser

.NET key value configuration parser
C#
1
star
18

Nager.BedLight

bed light with motion detector
C++
1
star
19

Nager.BathControl

BathControl is a smart fan control with humidity sensor and a ESP8266
Lua
1
star
20

Nager.Authentication

asp.net webapi headless authentication
C#
1
star