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.
- โ 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
Add this to your package's pubspec.yaml file:
dependencies:
country_holiday: ^0.0.1Then run:
dart pub getYou need a Google Calendar API key to use this library:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Calendar API:
- Navigate to "APIs & Services" โ "Library"
- Search for "Google Calendar API"
- Click "Enable"
- Create credentials:
- Go to "APIs & Services" โ "Credentials"
- Click "Create Credentials" โ "API Key"
- Copy your API key
- (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
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');
}// 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}');
}
}The library supports 100+ countries worldwide via Google Calendar's public holiday calendars:
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
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
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
๐ฎ๐ฑ IL, ๐ธ๐ฆ SA, ๐ฆ๐ช AE, ๐ถ๐ฆ QA, ๐ฐ๐ผ KW, ๐ง๐ญ BH, ๐ด๐ฒ OM, ๐ฏ๐ด JO, ๐ฑ๐ง LB, ๐น๐ท TR, ๐ฎ๐ท IR
North Africa: ๐ช๐ฌ EG, ๐ฒ๐ฆ MA, ๐น๐ณ TN, ๐ฉ๐ฟ DZ, ๐ฑ๐พ LY
Sub-Saharan Africa: ๐ฟ๐ฆ ZA, ๐ณ๐ฌ NG, ๐ฐ๐ช KE, ๐ฌ๐ญ GH, ๐ช๐น ET, ๐น๐ฟ TZ, ๐บ๐ฌ UG
๐ฆ๐บ 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.
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) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- 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
Main facade for accessing holiday data.
CountryHolidays({required String apiKey})Requires a valid Google Calendar API key.
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);Future<List<Holiday>> getHolidaysByMonth(String countryCode, int year, int month)Get holidays for a specific month.
countryCode: ISO 3166-1 alpha-2 codeyear: Year to querymonth: 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);Future<List<Holiday>> getHolidaysByDate(String countryCode, DateTime date)Get holidays on a specific date.
countryCode: ISO 3166-1 alpha-2 codedate: 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);Future<bool> isHoliday(String countryCode, DateTime date)Check if a date is a holiday.
countryCode: ISO 3166-1 alpha-2 codedate: Date to check (time component ignored)- Returns:
trueif at least one holiday exists on that date
Example:
final isHoliday = await countryHolidays.isHoliday('US', DateTime(2025, 7, 4));
print(isHoliday); // true (Independence Day)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');class Holiday {
final String name;
final DateTime date;
final String? description;
final bool isPublic;
final HolidayType type;
}enum HolidayType {
national, // National/Independence days
religious, // Religious holidays
observance, // Observance days
cultural, // Cultural celebrations
}class Country {
final String code; // ISO 3166-1 alpha-2
final String name; // Full country name
}To add support for a new country's Google Calendar:
- Find the Google Calendar ID for the country's public holidays
- 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',
};- Add the country name mapping in
google_calendar_data_source.dart:
const countryNames = {
// ... existing countries
'MX': 'Mexico',
};- Run tests to verify:
dart testdart testdart run example/example.dartdart analyzeThis project is open source and available under the Apache License 2.0.
- 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
Built with โค๏ธ using Dart, clean architecture principles, and Google Calendar API.
Holiday data provided by Google Calendar's public holiday calendars.