thai_holidays 0.1.0 copy "thai_holidays: ^0.1.0" to clipboard
thai_holidays: ^0.1.0 copied to clipboard

Pure-Dart Thai public-holiday calendar: fixed and movable Buddhist holidays, in-lieu days, special bridge days, and business-day helpers.

example/main.dart

import 'package:thai_holidays/thai_holidays.dart';

String _d(DateTime d) => d.toUtc().toIso8601String().substring(0, 10);

void main() {
  // 2026 is an athikamat (double-eighth-month) leap year, so the Buddhist
  // holidays are shifted later than in an ordinary year.
  print('Thai public holidays for 2026 (athikamat / leap year):\n');
  for (final h in thaiHolidays(2026)) {
    final tag = '[${h.type.name}]'.padRight(15);
    final obs =
        h.observedFor != null ? '  (in lieu of ${_d(h.observedFor!)})' : '';
    print('${_d(h.date)}  $tag ${h.nameEn}$obs');
  }

  print('\nBuddhist (lunar) holidays only:\n');
  for (final h
      in thaiHolidays(2026).where((h) => h.type == ThaiHolidayType.lunar)) {
    print('${_d(h.date)}  ${h.nameEn}  (${h.nameTh})');
  }

  print('\nGovernment-only holidays (NOT Bank of Thailand bank holidays):');
  for (final h in thaiHolidays(2026, includeSubstitution: false)
      .where((h) => !h.bankHoliday)) {
    print('  ${_d(h.date)}  ${h.name(thai: false)}  (id: ${h.id.name})');
  }

  print('\nIdentify a holiday by stable id (no string matching):');
  final onNewYear = holidayOn(DateTime.utc(2026, 1, 1));
  print('  holidayOn(2026-01-01) = ${onNewYear?.id.name} '
      '/ ${onNewYear?.name()} / ${onNewYear?.name(thai: false)}');

  print('\nRange query across a year boundary:');
  for (final h in thaiHolidaysBetween(
      DateTime.utc(2025, 12, 28), DateTime.utc(2026, 1, 5))) {
    print('  ${_d(h.date)}  ${h.name(thai: false)}  [${h.type.name}]');
  }

  print('\nBusiness-day helpers:');
  print('  isBusinessDay(2026-01-01) = '
      '${isBusinessDay(DateTime.utc(2026, 1, 1))}');
  print('  nextBusinessDay(2025-12-31) = '
      '${_d(nextBusinessDay(DateTime.utc(2025, 12, 31)))}');
  print('  addBusinessDays(2026-04-10, 5) = '
      '${_d(addBusinessDays(DateTime.utc(2026, 4, 10), 5))}');
  print('  businessDaysBetween(2026-04-01, 2026-04-30) = '
      '${businessDaysBetween(DateTime.utc(2026, 4, 1), DateTime.utc(2026, 4, 30))}');
}
0
likes
160
points
37
downloads

Documentation

API reference

Publisher

verified publisher10v3n4m.cc

Weekly Downloads

Pure-Dart Thai public-holiday calendar: fixed and movable Buddhist holidays, in-lieu days, special bridge days, and business-day helpers.

Repository (GitHub)
View/report issues

Topics

#thai #holiday #calendar #buddhist #date

License

MIT (license)

Dependencies

thai_lunar

More

Packages that depend on thai_holidays