Skip to content

Tempo Plugin

@magmacomputing/tempo-plugin-holidays ​

npm version npm peer dependency version License TypeScript Ready

The Regional Holidays Plugin provides bank holiday resolution, weekend observation shifts, SLA working hours calculations, and business day arithmetic for Tempo.


Key Features ​

  • Zero-Latency Built-in Calendars: Instant synchronous holiday calculation for US, Australia, United Kingdom, Canada, Germany, France, Japan, and New Zealand.
  • t.geo.country Resolution Cascade: Automatically resolves national calendars via explicit option, tempo.geo.country, tempo.intl.region, or BCP-47 tempo.locale.
  • Global Long-Tail Coverage (100+ Countries): Dynamic async preloading via @magmacomputing/tempo-fns with automatic 24-hour TTL caching in runtime storage.
  • SLA Working Hours Calculation: t.holidays.workingHoursUntil(deadline) calculates business hours between dates, taking into account working hour windows, weekends, and regional holidays.
  • Cultural Weekend Awareness: Automatically respects cultural workweeks (e.g. Friday/Saturday weekend in Middle Eastern locales like ar-SA).

Installation ​

bash
npm install @magmacomputing/tempo-plugin-holidays

Quickstart ​

Interactive Demo (@magmacomputing/tempo-plugin-holidays)
Open in Full REPL↗
// 🏖️ Regional Public Holidays & SLA Business Days (@magmacomputing/tempo-plugin-holidays)
const { HolidaysPlugin } = await import('@magmacomputing/tempo-plugin-holidays');
Tempo.use(HolidaysPlugin);

// 1. Evaluate holiday by country or instance geo metadata
const christmas = new Tempo('2026-12-25', { geo: { country: 'US' } });
console.log('Is Christmas Day holiday in US?', christmas.holidays.isHoliday());
console.log('Holiday Name:', christmas.holidays.name);
console.log('Is Business Day?', christmas.holidays.isBusinessDay());

// 2. Next & previous business day arithmetic
const nextWorkDay = christmas.holidays.nextBusinessDay();
console.log('Next Business Day after Christmas:', nextWorkDay.format('{www}, {dd} {mon} {yyyy}'));

// 3. Add N working business days
const deadline = christmas.holidays.addBusinessDays(5);
console.log('5 Business Days later:', deadline.format('{www}, {dd} {mon} {yyyy}'));

// 4. SLA Working Hours calculation
const ticketOpened = new Tempo('2026-01-23 15:00:00', { geo: { country: 'AU' } });
const ticketResolved = new Tempo('2026-01-27 11:00:00', { geo: { country: 'AU' } });
const hours = ticketOpened.holidays.workingHoursUntil(ticketResolved);
console.log('SLA Working Hours (9am-5pm window):', hours, 'hours');

return `Christmas: ${christmas.holidays.name} (Next work day: ${nextWorkDay.format('{www}, {dd} {mon}')})`;
Executes 100% in browser via native ESM sandbox
typescript
import '@magmacomputing/tempo-plugin-holidays/install';
import { Tempo } from '@magmacomputing/tempo';

// Australia Day (Jan 26)
const t = new Tempo('2026-01-26', { geo: { country: 'AU' } });

console.log(t.holidays.isHoliday());          // true
console.log(t.holidays.name);                 // 'Australia Day'
console.log(t.holidays.isBusinessDay());      // false

// Advance to next valid business day past holidays & weekends
const nextWorkDay = t.holidays.nextBusinessDay();
console.log(nextWorkDay.format('{yyyy}-{mm}-{dd}')); // '2026-01-27'

// Calculate SLA working hours between dates
const start = new Tempo('2026-01-23 15:00:00', { geo: { country: 'AU' } }); // Friday 3pm
const deadline = new Tempo('2026-01-27 11:00:00', { geo: { country: 'AU' } }); // Tuesday 11am
console.log(start.holidays.workingHoursUntil(deadline)); // 4.0 hours (2h Fri + 0h Sat/Sun/Mon-Holiday + 2h Tue)

Topic Guides ​


License ​

This is a Community plugin. It is completely free and open-source for personal and commercial use under the MIT license. No license token is required.

Released under the MIT License.