Ejemplos
IsHoliday
Verifica si una fecha específica es un feriado público en Perú.
using Vali_Holiday.Core;
using Vali_Holiday.Providers;
var holiday = new ValiHoliday();
holiday.Register(new PeruHolidayProvider());
var date = new DateTime(2025, 7, 28);
bool isHoliday = holiday.IsHoliday("PE", date);
Console.WriteLine($"{date:yyyy-MM-dd} is a holiday in Peru: {isHoliday}");
// → 2025-07-28 is a holiday in Peru: True (Día de la Independencia del Perú)
Pruébalo en vivo
▶ Abrir en dotnetfiddle — Agrega el paquete NuGet Vali-Holiday en la configuración del fiddle.
GetHolidays
Lista todos los feriados públicos de un país en un año dado.
using Vali_Holiday.Core;
using Vali_Holiday.Providers;
var holiday = new ValiHoliday();
holiday.Register(new MexicoHolidayProvider());
var holidays = holiday.GetHolidays("MX", 2025)
.OrderBy(h => h.Date);
Console.WriteLine("Public holidays in Mexico — 2025:");
foreach (var h in holidays)
Console.WriteLine($" {h.Date:ddd, MMM dd} — {h.Name} ({h.Type})");
Pruébalo en vivo
▶ Abrir en dotnetfiddle — Agrega el paquete NuGet Vali-Holiday en la configuración del fiddle.
IsLongWeekend
Verifica si una fecha forma parte de un fin de semana largo (un feriado adyacente a un fin de semana).
using Vali_Holiday.Core;
using Vali_Holiday.Providers;
var holiday = new ValiHoliday();
holiday.Register(new UsaHolidayProvider());
// El Memorial Day 2025 cae el lunes 26 de mayo
var date = new DateTime(2025, 5, 26);
bool isLong = holiday.IsLongWeekend("US", date);
Console.WriteLine($"{date:yyyy-MM-dd} is a long weekend in the US: {isLong}");
// → 2025-05-26 is a long weekend in the US: True
Pruébalo en vivo
▶ Abrir en dotnetfiddle — Agrega el paquete NuGet Vali-Holiday en la configuración del fiddle.
HolidayProviderFactory.CreateLatinAmerica()
Registra proveedores de feriados para todos los países latinoamericanos de una vez usando la fábrica.
using Vali_Holiday.Core;
using Vali_Holiday.Providers;
var holiday = new ValiHoliday();
// Registrar todos los países de América Latina en una sola llamada
foreach (var provider in HolidayProviderFactory.CreateLatinAmerica())
holiday.Register(provider);
var countries = holiday.SupportedCountries().OrderBy(c => c);
Console.WriteLine($"Registered {countries.Count()} Latin American countries:");
foreach (var code in countries)
Console.WriteLine($" {code}");
// Consultar un feriado en múltiples países en la misma fecha (Navidad)
var christmas = new DateTime(2025, 12, 25);
foreach (var code in new[] { "PE", "MX", "AR", "CO", "CL" })
{
bool isHoliday = holiday.IsHoliday(code, christmas);
Console.WriteLine($" {code}: Christmas is a holiday = {isHoliday}");
}
Pruébalo en vivo
▶ Abrir en dotnetfiddle — Agrega el paquete NuGet Vali-Holiday en la configuración del fiddle.