Articles

Iranian holidays in Dart and Flutter, offline or online

Calculate Iranian official holidays, lunar Hijri holidays and working days in Dart and Flutter with iranian_holidays, without a network call, or fetch them from an online source.

Most holiday packages call a web service. Iranian holidays are harder: half of them follow the lunar Hijri calendar and move about 11 days earlier each Jalali year, and services for them are community projects or paid plans. iranian_holidays calculates them on the device, and can also read them from an online source.

Install

sh
dart pub add iranian_holidays

It builds on jalali_date, so every date is a PersianDate.

Is this day a holiday?

dart
import 'package:jalali_date/jalali_date.dart';
import 'package:iranian_holidays/iranian_holidays.dart';

void main() {
  final offline = OfflineHolidaySource();

  final day = offline.dayOf(PersianDate(1405, 4, 4));
  print(day.isHoliday); // true
  print(day.holidays.first.description); // عاشورا

  print(offline.hijriDate(PersianDate(1405, 1, 1))); // 1 شوال 1447
}

dayOf, holidaysOf and hijriDate are synchronous. holidaysOf(1405) lists the 26 official days off of a Jalali year, not counting Fridays.

Working days

dart
print(offline.isWorkingDay(PersianDate(1405, 1, 13))); // false, Nature Day
print(offline.addWorkingDays(PersianDate(1405, 1, 1), 3)); // 1405/01/08

Pass weekend: {DateTime.thursday, DateTime.friday} if your week ends on Thursday.

How accurate is the offline mode?

A Hijri month starts the day after the new crescent is first seen in Iran. The package computes the Sun and the Moon at sunset and applies Yallop's visibility criterion at eight Iranian cities. Up to Jalali 1405 the month starts come from the official calendars of the University of Tehran, so past and current holidays match the published calendar. Against the 259 months published from 1427 to 1448 (Hijri), the calculation alone gets 242 right and is one day off for 17. When an announcement differs, pass the start yourself with hijriMonthStarts, or use an online source.

Online sources

HolidayApiIrSource (free, no key), CalendarificSource and GoogleCalendarSource return more events than the 26 official days. You can fall back from an online source to the offline calculation when the request fails. The holidays documentation compares them, including limits such as CORS on Flutter web. Whatever you use, tell your users where the data comes from; HolidaySource.name, website and notice hold that text.