Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Holidays Laravel Package

spatie/holidays

Calculate public holidays for supported countries in PHP. Fetch holidays for the current or a specific year using an ISO country code or country class (with region-based holidays). Simple API: Holidays::for(...)->get() returns an array of holiday dates/names.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Lightweight & Modular: The package is a pure PHP library with no external dependencies (beyond Laravel’s core), making it ideal for integration into existing Laravel applications without architectural disruption.
  • Domain-Specific: Holidays are a cross-cutting concern (e.g., scheduling, payroll, UI adjustments). Centralizing logic here reduces duplication and improves maintainability.
  • Stateless & Cacheable: Holiday calculations are deterministic (based on country/year) and can be cached aggressively (e.g., Redis, Laravel’s cache), minimizing runtime overhead.

Integration Feasibility

  • Laravel Native: Works seamlessly with Laravel’s service container, facades, and caching systems. Can be injected via dependency injection or accessed via a facade (Holidays::for('us')->get()).
  • Database Agnostic: No ORM or database schema changes required. Holidays can be stored in memory, cached, or even serialized to a database if needed.
  • Extensible: Supports custom holiday rules via Holiday model events or by extending the package’s HolidayRepository (though this requires deeper customization).

Technical Risk

  • Data Accuracy: Holidays are politically sensitive (e.g., regional variations, last-minute changes). The package relies on Spatie’s maintained dataset, but edge cases (e.g., COVID-19 adjustments, new territories) may require manual overrides.
  • Performance: For high-traffic apps, uncached calls to get() could become a bottleneck. Mitigation: Pre-load holidays at app boot or use Laravel’s booted callback.
  • Time Zone Awareness: The package doesn’t handle time zones explicitly. If your app uses time zones (e.g., for scheduling), ensure consistency between holiday dates and timezone-aware logic.
  • Future-Proofing: The package is MIT-licensed and actively maintained, but long-term reliance on Spatie’s dataset could be risky if the project is abandoned. Consider a fallback mechanism (e.g., local overrides).

Key Questions

  1. Use Case Scope:
    • Will holidays be used for business logic (e.g., payroll, deadlines) or just UI/UX (e.g., disabling buttons)?
    • Are regional holidays (e.g., US state-specific) or international holidays (e.g., UN days) needed?
  2. Data Freshness:
    • How often do holidays change in your target countries? Is a yearly update sufficient, or are real-time adjustments needed?
  3. Caching Strategy:
    • Should holidays be cached globally (e.g., Redis) or per-user (e.g., for multi-tenant apps)?
  4. Customization Needs:
    • Do you need to add company-specific holidays or override defaults? If so, how will these be managed (e.g., database table, config file)?
  5. Testing:
    • How will you test holiday logic? Unit tests for edge cases (e.g., leap years, moving holidays like Easter) are critical.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Perfect fit for Laravel apps due to:
    • Native Composer integration.
    • Compatibility with Laravel’s service container, caching, and facades.
    • Easy integration with Laravel’s scheduling (e.g., Artisan::schedule()) or event system (e.g., HolidayAdded events).
  • PHP Versions: Supports PHP 8.1+, aligning with Laravel’s LTS support.
  • Database: No schema changes required, but can be extended to store custom holidays in a holidays table if needed.

Migration Path

  1. Installation:
    composer require spatie/holidays
    
    Publish config (if needed) via:
    php artisan vendor:publish --provider="Spatie\Holidays\HolidaysServiceProvider"
    
  2. Basic Integration:
    • Use the facade in controllers/services:
      $holidays = \Spatie\Holidays\Holidays::for('be')->get();
      
    • Or inject the Holidays class via constructor.
  3. Advanced Integration:
    • Caching: Wrap calls in Laravel’s cache:
      $holidays = Cache::remember("holidays-be-{$year}", now()->addYear(), fn() => Holidays::for('be')->get());
      
    • Custom Holidays: Extend the HolidayRepository or add a middleware to merge custom holidays:
      // config/holidays.php
      'custom' => [
          'be' => [
              '2024-12-25' => 'Company Holiday',
          ],
      ];
      
    • Database Storage: Create a holidays table and hydrate it at app boot:
      // AppServiceProvider@boot
      Holidays::for(config('app.country'))->get()->each(fn($holiday) => Holiday::updateOrCreate(...));
      

Compatibility

  • Laravel Versions: Tested with Laravel 9+. For older versions, check Packagist for compatibility or use a branch/tag.
  • PHP Extensions: None required beyond standard PHP.
  • Third-Party Conflicts: Low risk; the package is isolated and doesn’t rely on global state.

Sequencing

  1. Phase 1: Core Integration
    • Install and test basic holiday retrieval.
    • Implement caching for performance.
  2. Phase 2: Business Logic
    • Integrate with scheduling (e.g., disable tasks on holidays).
    • Add holiday checks to API responses or UI (e.g., is_holiday flag).
  3. Phase 3: Customization
    • Add custom holidays via config/database.
    • Extend for multi-country or regional support if needed.
  4. Phase 4: Monitoring
    • Log holiday-related errors (e.g., missing dates).
    • Set up alerts for data updates (e.g., via GitHub releases).

Operational Impact

Maintenance

  • Vendor Updates: Monitor Spatie’s releases for holiday data updates. Use Composer’s update or Laravel’s package:update to patch.
  • Custom Logic: If extending the package (e.g., custom holidays), document the logic and test updates thoroughly.
  • Deprecation: The package is MIT-licensed and actively maintained, but plan for a migration path if Spatie deprioritizes it (e.g., fork or switch to a local dataset).

Support

  • Troubleshooting:
    • Common issues: Incorrect country codes, cached stale data, or timezone mismatches.
    • Debugging: Use dd(Holidays::for('us')->get()) to inspect raw data.
  • Community: Limited to Spatie’s GitHub issues (393 stars but low activity). For critical issues, consider opening a PR or contacting Spatie directly.
  • Documentation: README and changelog are clear, but custom use cases may require internal docs.

Scaling

  • Performance:
    • Cold Start: First call to get() may take ~50–200ms (depends on country complexity). Mitigate with caching.
    • Hot Start: Cached calls are O(1) and negligible.
    • High Traffic: Distribute cache (e.g., Redis cluster) if holidays are accessed globally.
  • Data Volume: Holiday lists are small (typically <100 entries/year/country). No scalability concerns unless supporting thousands of countries/regions.
  • Database: If storing custom holidays, ensure the holidays table is indexed by country and date.

Failure Modes

Failure Scenario Impact Mitigation
Package update breaks logic Holiday data errors Test updates in staging; use composer why-not to check dependencies.
Caching issues Stale holiday data Use short TTLs (e.g., 1 day) or invalidate cache on app updates.
Country code mismatch Wrong holidays returned Validate country codes early (e.g., middleware).
Custom holiday logic fails Inconsistent overrides Unit test custom holiday merges.
Timezone conflicts Holiday dates misaligned Normalize to UTC or app’s default timezone.

Ramp-Up

  • Developer Onboarding:
    • Time Required: 1–2 hours to integrate basics; 4–8 hours for customizations.
    • Key Tasks:
      1. Install and test Holidays::for()->get().
      2. Set up caching.
      3. Document country codes and custom holiday rules.
  • Testing Strategy:
    • Unit Tests: Mock Holidays class to test holiday-aware logic (e.g., "skip task if holiday").
    • Edge Cases: Test leap years, moving holidays (e.g., Easter), and regional variations.
    • Integration Tests: Verify caching and custom holiday overrides.
  • Documentation:
    • Internal wiki for:
      • Supported country codes.
      • Custom holiday configuration.
      • Cache invalidation procedures.
  • Training:
    • Short workshop on:
      • How to add/remove holidays.
      • Debugging
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4