Voile.Schema.System.LibHoliday (Voile v0.1.26)

Copy Markdown View Source

Summary

Functions

Calculate business days between two dates, excluding weekends and holidays. This is the core function used for fine calculation.

Holiday and schedule changeset for creating and updating entries.

Get business days for the current week. Returns list of day numbers that are business days.

Get all active holidays within a date range.

Get non-business days for the current week. Returns list of day numbers that are non-business days.

Get the current weekly schedule configuration. Returns a map with day names as keys and business status as values.

Check if weekly schedule has been configured.

Checks if a date is a custom holiday from the database. @deprecated Use is_specific_holiday?/1 instead

Checks if a given date is a holiday or non-business day. This includes both specific holidays and weekly schedule non-business days. Considers both unit-specific and system-wide rules. Uses ETS caching to avoid repeated database queries.

Checks if a date is a non-business day according to the weekly schedule. This replaces the old hardcoded weekend check. Checks both unit-specific and system-wide schedules. Uses caching to avoid repeated queries for the same day of week.

Checks if a date is a specific holiday from the database. Checks both unit-specific and system-wide holidays. Uses caching to avoid repeated queries for the same date.

Legacy function - checks if a date is a weekend (Saturday or Sunday). Now uses the weekly schedule system, but falls back to hardcoded if no schedule exists.

Set up default weekly schedule (Monday-Friday business, Saturday-Sunday non-business).

Update a specific day's business status in the weekly schedule.

Functions

business_days_between(start_date, end_date, unit_id \\ nil)

Calculate business days between two dates, excluding weekends and holidays. This is the core function used for fine calculation.

changeset(lib_holiday, attrs)

Holiday and schedule changeset for creating and updating entries.

Schedule Types:

  • "holiday" - Specific date holidays (uses holiday_date field)
  • "schedule" - Weekly recurring schedule (uses day_of_week field)

Holiday Types (for schedule_type: "holiday"):

  • "public" - Public holidays (national/local government holidays)
  • "library" - Library-specific holidays (closure days, maintenance days)
  • "custom" - Custom holidays defined by the library

Holiday Types (for schedule_type: "schedule"):

  • "non_business" - Regular non-business days (e.g., weekends)
  • "business" - Regular business days (for reference/override)

clear_cache()

get_business_days()

Get business days for the current week. Returns list of day numbers that are business days.

get_holidays_in_range(start_date, end_date)

Get all active holidays within a date range.

get_non_business_days()

Get non-business days for the current week. Returns list of day numbers that are non-business days.

get_weekly_schedule(unit_id \\ nil)

Get the current weekly schedule configuration. Returns a map with day names as keys and business status as values.

has_weekly_schedule?()

Check if weekly schedule has been configured.

is_custom_holiday?(date)

Checks if a date is a custom holiday from the database. @deprecated Use is_specific_holiday?/1 instead

is_holiday?(date, unit_id \\ nil)

Checks if a given date is a holiday or non-business day. This includes both specific holidays and weekly schedule non-business days. Considers both unit-specific and system-wide rules. Uses ETS caching to avoid repeated database queries.

is_non_business_day_by_schedule?(date, unit_id \\ nil)

Checks if a date is a non-business day according to the weekly schedule. This replaces the old hardcoded weekend check. Checks both unit-specific and system-wide schedules. Uses caching to avoid repeated queries for the same day of week.

is_specific_holiday?(date, unit_id \\ nil)

Checks if a date is a specific holiday from the database. Checks both unit-specific and system-wide holidays. Uses caching to avoid repeated queries for the same date.

is_weekend?(date)

Legacy function - checks if a date is a weekend (Saturday or Sunday). Now uses the weekly schedule system, but falls back to hardcoded if no schedule exists.

setup_default_weekly_schedule(unit_id \\ nil)

Set up default weekly schedule (Monday-Friday business, Saturday-Sunday non-business).

update_day_schedule(day_of_week, is_business_day, description \\ nil, unit_id \\ nil)

Update a specific day's business status in the weekly schedule.