Skip to content

DecksPlayer/country_holidays

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Country Holiday Library

A Dart library for accessing holiday data from Google Calendar's public holiday calendars. Built following clean architecture principles with global coverage of 100+ countries.

Features

  • โœ… 100+ Countries: Comprehensive global coverage across all continents
  • โœ… Clean Architecture: Domain, Data, and Use Case layers
  • โœ… Real-time Data: Always up-to-date holidays from Google Calendar API
  • โœ… Type-Safe: Full null safety support
  • โœ… Simple API: Easy-to-use facade pattern
  • โœ… Well-Tested: Comprehensive test coverage

Installation

1. Add Dependency

Add this to your package's pubspec.yaml file:

dependencies:
  country_holiday: ^0.0.1

Then run:

dart pub get

2. Get Google Calendar API Key

You need a Google Calendar API key to use this library:

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Google Calendar API:
    • Navigate to "APIs & Services" โ†’ "Library"
    • Search for "Google Calendar API"
    • Click "Enable"
  4. Create credentials:
    • Go to "APIs & Services" โ†’ "Credentials"
    • Click "Create Credentials" โ†’ "API Key"
    • Copy your API key
  5. (Optional) Restrict your API key:
    • Click on your API key to edit it
    • Under "API restrictions", select "Restrict key"
    • Choose "Google Calendar API"
    • Save changes

Usage

Basic Example

import 'package:country_holiday/country_holiday.dart';

void main() async {
  // Initialize with your Google Calendar API key
  const apiKey = 'YOUR_GOOGLE_API_KEY_HERE';
  final countryHolidays = CountryHolidays(apiKey: apiKey);

  // Get all holidays for a country
  final usHolidays = await countryHolidays.getHolidaysByCountry('US');
  print('US has ${usHolidays.length} holidays');

  // Check if a specific date is a holiday
  final isHoliday = await countryHolidays.isHoliday('US', DateTime(2025, 7, 4));
  print('Is July 4th a US holiday? $isHoliday'); // true

  // Get all available countries
  final countries = await countryHolidays.getAllCountries();
  print('${countries.length} countries available');
}

Advanced Usage

// Get holidays on a specific date
final christmas = DateTime(2025, 12, 25);
final holidays = await countryHolidays.getHolidaysByDate('US', christmas);
print(holidays.first.name); // "Christmas"

// Filter by holiday type
final usHolidays = await countryHolidays.getHolidaysByCountry('US');
final nationalHolidays = usHolidays
    .where((h) => h.type == HolidayType.national)
    .toList();

// Access holiday details
for (var holiday in usHolidays) {
  print('${holiday.name} - ${holiday.date}');
  print('Type: ${holiday.type}');
  print('Public: ${holiday.isPublic}');
  if (holiday.description != null) {
    print('Description: ${holiday.description}');
  }
}

Supported Countries

The library supports 100+ countries worldwide via Google Calendar's public holiday calendars:

๐ŸŒŽ Americas (20 countries)

North America: ๐Ÿ‡บ๐Ÿ‡ธ US, ๐Ÿ‡จ๐Ÿ‡ฆ CA, ๐Ÿ‡ฒ๐Ÿ‡ฝ MX

Central America & Caribbean: ๐Ÿ‡จ๐Ÿ‡ท CR, ๐Ÿ‡ต๐Ÿ‡ฆ PA, ๐Ÿ‡ฉ๐Ÿ‡ด DO, ๐Ÿ‡ฌ๐Ÿ‡น GT, ๐Ÿ‡ญ๐Ÿ‡ณ HN, ๐Ÿ‡ณ๐Ÿ‡ฎ NI, ๐Ÿ‡ธ๐Ÿ‡ป SV

South America: ๐Ÿ‡ฆ๐Ÿ‡ท AR, ๐Ÿ‡ง๐Ÿ‡ท BR, ๐Ÿ‡จ๐Ÿ‡ฑ CL, ๐Ÿ‡จ๐Ÿ‡ด CO, ๐Ÿ‡ต๐Ÿ‡ช PE, ๐Ÿ‡ป๐Ÿ‡ช VE, ๐Ÿ‡ช๐Ÿ‡จ EC, ๐Ÿ‡บ๐Ÿ‡พ UY, ๐Ÿ‡ง๐Ÿ‡ด BO, ๐Ÿ‡ต๐Ÿ‡พ PY

๐ŸŒ Europe (33 countries)

Western Europe: ๐Ÿ‡ฌ๐Ÿ‡ง GB, ๐Ÿ‡ฎ๐Ÿ‡ช IE, ๐Ÿ‡ซ๐Ÿ‡ท FR, ๐Ÿ‡ฉ๐Ÿ‡ช DE, ๐Ÿ‡ณ๐Ÿ‡ฑ NL, ๐Ÿ‡ง๐Ÿ‡ช BE, ๐Ÿ‡ฑ๐Ÿ‡บ LU, ๐Ÿ‡จ๐Ÿ‡ญ CH, ๐Ÿ‡ฆ๐Ÿ‡น AT

Southern Europe: ๐Ÿ‡ช๐Ÿ‡ธ ES, ๐Ÿ‡ต๐Ÿ‡น PT, ๐Ÿ‡ฎ๐Ÿ‡น IT, ๐Ÿ‡ฌ๐Ÿ‡ท GR, ๐Ÿ‡ญ๐Ÿ‡ท HR, ๐Ÿ‡ธ๐Ÿ‡ฎ SI

Northern Europe: ๐Ÿ‡ธ๐Ÿ‡ช SE, ๐Ÿ‡ณ๐Ÿ‡ด NO, ๐Ÿ‡ฉ๐Ÿ‡ฐ DK, ๐Ÿ‡ซ๐Ÿ‡ฎ FI, ๐Ÿ‡ฎ๐Ÿ‡ธ IS

Eastern Europe: ๐Ÿ‡ต๐Ÿ‡ฑ PL, ๐Ÿ‡จ๐Ÿ‡ฟ CZ, ๐Ÿ‡ธ๐Ÿ‡ฐ SK, ๐Ÿ‡ญ๐Ÿ‡บ HU, ๐Ÿ‡ท๐Ÿ‡ด RO, ๐Ÿ‡ง๐Ÿ‡ฌ BG, ๐Ÿ‡บ๐Ÿ‡ฆ UA, ๐Ÿ‡ท๐Ÿ‡บ RU, ๐Ÿ‡ฑ๐Ÿ‡น LT, ๐Ÿ‡ฑ๐Ÿ‡ป LV, ๐Ÿ‡ช๐Ÿ‡ช EE, ๐Ÿ‡ท๐Ÿ‡ธ RS

๐ŸŒ Asia (21 countries)

East Asia: ๐Ÿ‡จ๐Ÿ‡ณ CN, ๐Ÿ‡ฏ๐Ÿ‡ต JP, ๐Ÿ‡ฐ๐Ÿ‡ท KR, ๐Ÿ‡น๐Ÿ‡ผ TW, ๐Ÿ‡ญ๐Ÿ‡ฐ HK, ๐Ÿ‡ฒ๐Ÿ‡ด MO

Southeast Asia: ๐Ÿ‡น๐Ÿ‡ญ TH, ๐Ÿ‡ป๐Ÿ‡ณ VN, ๐Ÿ‡ต๐Ÿ‡ญ PH, ๐Ÿ‡ฎ๐Ÿ‡ฉ ID, ๐Ÿ‡ฒ๐Ÿ‡พ MY, ๐Ÿ‡ธ๐Ÿ‡ฌ SG, ๐Ÿ‡ฑ๐Ÿ‡ฆ LA

South Asia: ๐Ÿ‡ฎ๐Ÿ‡ณ IN, ๐Ÿ‡ต๐Ÿ‡ฐ PK, ๐Ÿ‡ง๐Ÿ‡ฉ BD, ๐Ÿ‡ฑ๐Ÿ‡ฐ LK

Central Asia: ๐Ÿ‡ฐ๐Ÿ‡ฟ KZ, ๐Ÿ‡บ๐Ÿ‡ฟ UZ

๐Ÿ•Œ Middle East (11 countries)

๐Ÿ‡ฎ๐Ÿ‡ฑ IL, ๐Ÿ‡ธ๐Ÿ‡ฆ SA, ๐Ÿ‡ฆ๐Ÿ‡ช AE, ๐Ÿ‡ถ๐Ÿ‡ฆ QA, ๐Ÿ‡ฐ๐Ÿ‡ผ KW, ๐Ÿ‡ง๐Ÿ‡ญ BH, ๐Ÿ‡ด๐Ÿ‡ฒ OM, ๐Ÿ‡ฏ๐Ÿ‡ด JO, ๐Ÿ‡ฑ๐Ÿ‡ง LB, ๐Ÿ‡น๐Ÿ‡ท TR, ๐Ÿ‡ฎ๐Ÿ‡ท IR

๐ŸŒ Africa (12 countries)

North Africa: ๐Ÿ‡ช๐Ÿ‡ฌ EG, ๐Ÿ‡ฒ๐Ÿ‡ฆ MA, ๐Ÿ‡น๐Ÿ‡ณ TN, ๐Ÿ‡ฉ๐Ÿ‡ฟ DZ, ๐Ÿ‡ฑ๐Ÿ‡พ LY

Sub-Saharan Africa: ๐Ÿ‡ฟ๐Ÿ‡ฆ ZA, ๐Ÿ‡ณ๐Ÿ‡ฌ NG, ๐Ÿ‡ฐ๐Ÿ‡ช KE, ๐Ÿ‡ฌ๐Ÿ‡ญ GH, ๐Ÿ‡ช๐Ÿ‡น ET, ๐Ÿ‡น๐Ÿ‡ฟ TZ, ๐Ÿ‡บ๐Ÿ‡ฌ UG

๐ŸŒ Oceania (4 countries)

๐Ÿ‡ฆ๐Ÿ‡บ AU, ๐Ÿ‡ณ๐Ÿ‡ฟ NZ, ๐Ÿ‡ซ๐Ÿ‡ฏ FJ, ๐Ÿ‡ต๐Ÿ‡ฌ PG


Total: 100+ countries across all continents with real-time holiday data from Google Calendar.

Note

Holiday data is provided by Google Calendar's public holiday calendars and is automatically updated.

Architecture

This library follows Clean Architecture principles:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         Public API (Facade)         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚           Use Cases Layer           โ”‚
โ”‚  (Business Logic & Validation)      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚          Domain Layer               โ”‚
โ”‚  (Entities, Enums, Interfaces)      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚           Data Layer                โ”‚
โ”‚  (Models, Data Sources, Repos)      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Principles

  • Dependency Inversion: Domain layer has no dependencies
  • Single Responsibility: Each country in its own file
  • Open/Closed: Easy to extend without modifying existing code
  • DRY: No code duplication

API Reference

CountryHolidays

Main facade for accessing holiday data.

Constructor

CountryHolidays({required String apiKey})

Requires a valid Google Calendar API key.

Methods

getHolidaysByCountry
Future<List<Holiday>> getHolidaysByCountry(String countryCode, {int? year})

Get all holidays for a country.

  • countryCode: ISO 3166-1 alpha-2 code (e.g., 'US', 'AR', 'BR')
  • year: Optional. If not provided, returns current year's holidays
  • Returns: List of holidays sorted by date

Example:

// Current year
final holidays = await countryHolidays.getHolidaysByCountry('US');

// Specific year
final holidays2026 = await countryHolidays.getHolidaysByCountry('AR', year: 2026);
getHolidaysByMonth
Future<List<Holiday>> getHolidaysByMonth(String countryCode, int year, int month)

Get holidays for a specific month.

  • countryCode: ISO 3166-1 alpha-2 code
  • year: Year to query
  • month: Month (1-12) to query
  • Returns: List of holidays in that month

Example:

// Get December 2026 holidays in Argentina
final decemberHolidays = await countryHolidays.getHolidaysByMonth('AR', 2026, 12);
getHolidaysByDate
Future<List<Holiday>> getHolidaysByDate(String countryCode, DateTime date)

Get holidays on a specific date.

  • countryCode: ISO 3166-1 alpha-2 code
  • date: Date to check (time component ignored)
  • Returns: List of holidays on that date (empty if none)

Example:

final christmas = DateTime(2025, 12, 25);
final holidays = await countryHolidays.getHolidaysByDate('US', christmas);
isHoliday
Future<bool> isHoliday(String countryCode, DateTime date)

Check if a date is a holiday.

  • countryCode: ISO 3166-1 alpha-2 code
  • date: Date to check (time component ignored)
  • Returns: true if at least one holiday exists on that date

Example:

final isHoliday = await countryHolidays.isHoliday('US', DateTime(2025, 7, 4));
print(isHoliday); // true (Independence Day)
getAllCountries
Future<List<Country>> getAllCountries()

Get all available countries.

  • Returns: List of 100+ countries sorted by country code

Example:

final countries = await countryHolidays.getAllCountries();
print('${countries.length} countries available');

Holiday Entity

class Holiday {
  final String name;
  final DateTime date;
  final String? description;
  final bool isPublic;
  final HolidayType type;
}

HolidayType Enum

enum HolidayType {
  national,    // National/Independence days
  religious,   // Religious holidays
  observance,  // Observance days
  cultural,    // Cultural celebrations
}

Country Entity

class Country {
  final String code;  // ISO 3166-1 alpha-2
  final String name;  // Full country name
}

Contributing

Adding Support for a New Country

To add support for a new country's Google Calendar:

  1. Find the Google Calendar ID for the country's public holidays
  2. Add the mapping to lib/src/data/datasources/calendar_config.dart:
const Map<String, String> countryToCalendarId = {
  // ... existing countries
  'MX': 'es.mexican#holiday@group.v.calendar.google.com',
};
  1. Add the country name mapping in google_calendar_data_source.dart:
const countryNames = {
  // ... existing countries
  'MX': 'Mexico',
};
  1. Run tests to verify:
dart test

Development

Running Tests

dart test

Running the Example

dart run example/example.dart

Code Analysis

dart analyze

License

This project is open source and available under the Apache License 2.0.

Roadmap

  • Google Calendar API integration
  • Support for 100+ countries worldwide
  • Query holidays by year
  • Query holidays by month
  • Automatic deduplication of holidays
  • Environment variable support
  • Caching mechanism to reduce API calls
  • Regional/state-specific holidays
  • Offline mode with cached data
  • Rate limiting and quota management

Credits

Built with โค๏ธ using Dart, clean architecture principles, and Google Calendar API.

Holiday data provided by Google Calendar's public holiday calendars.

About

A Dart library for accessing holiday data from Google Calendar's public holiday calendars with clean architecture.

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages