Usage | holidays-go | Spatie       

 SPATIE  

holidays-go
===========

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Holidays-go](https://spatie.be/docs/holidays-go/v1)  Usage

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/holidays-go/v1) 

  Usage    
- [ Introduction ](https://spatie.be/docs/holidays-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/holidays-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/holidays-go/v1/usage)
- [ Adding a new country ](https://spatie.be/docs/holidays-go/v1/adding-a-country)
- [ Testing ](https://spatie.be/docs/holidays-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/holidays-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/holidays-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/holidays-go/v1/support-us)

 Usage
=====

You can get all holidays for a country by using the `Get` method. It returns a slice of `Holiday` values sorted by date.

```
import "github.com/spatie/holidays-go"

calendar, err := holidays.For("be", 2024)
if err != nil {
    return err
}
items, err := calendar.Get()
if err != nil {
    return err
}

for _, holiday := range items {
    fmt.Println(holiday.Name, holiday.Date, holiday.Type)
}
```

Pass a case-insensitive country code to `For`, or a custom `Provider` to `New`. Use `ForCurrentYear("be")` for the current local year. For Greece, use the ISO code `gr`. The EU abbreviation `el` remains supported as an alias.

`Holiday` supports JSON encoding:

```
encoded, err := json.Marshal(items[0])
// {"name":"Nieuwjaar","date":"2024-01-01","type":"national","region":null}
```

### Getting holidays for a specific year

```
calendar, err := holidays.For("be", 2024)
items, err := calendar.Get()
```

Years must be between 1 and 9999. Countries with lookup tables have narrower ranges and return `ErrUnsupportedYear` when they cannot calculate a year. `For` validates the code and Gregorian year, while `Get` calculates the country rules.

### Getting holidays between two dates

`InRange` returns all holidays between two dates, inclusive. Dates are swappable. Shorthand strings expand to the first day of the first bound and the last day of the second bound before swapping, matching PHP.

```
items, err := calendar.InRange("2024-01-01", "2024-12-31")
items, err = calendar.InRange("2024", "2025")
items, err = calendar.InRange("2024-06", "2025-05")
```

Use `Between(from, to)` for two `Date` values. Invalid dates return `ErrInvalidDate`, rather than normalizing February 30 or parsing natural-language strings.

### Getting holidays in a specific language

```
items, err := calendar.Locale("fr").Get()
```

If no translation exists for the given locale or name, the original holiday name is returned. With no explicit locale, the country's default locale is used. `Locale` returns a copy and does not modify `calendar`.

### Regional holidays

Some countries have region-specific holidays. Select a region using its exact, case-sensitive code:

```
germany, err := holidays.For("de", 2024)
if err != nil {
    return err
}
badenWuerttemberg, err := germany.Region("DE-BW")
if err != nil {
    return err
}
items, err := badenWuerttemberg.Get()

fmt.Println(germany.Regions()) // [DE-BW DE-BY DE-BE ...]
```

An invalid regional code returns `ErrInvalidRegion`. Calling `Region("")` restores the national calendar. Like PHP, countries without regional calendars ignore a region argument.

Portugal uses municipal holidays. Its regions are the municipalities, identified by `PT-` followed by the DICO code published by the INE. For example, select `PT-1106` for Lisboa. All 308 municipalities are supported. These are municipal codes, not ISO 3166-2 district codes. Without a region, only national holidays are returned. Holidays applying to the whole autonomous region of Madeira or the Azores are not currently included.

Countries that support regions are Australia, Bosnia and Herzegovina, Brazil, France, Germany, Malaysia, Portugal, Spain and Switzerland.

### Determining if a date is a holiday

```
day, err := holidays.ParseDate("2024-01-01")
if err != nil {
    return err
}
yes, err := calendar.IsHoliday(day)
```

The query uses the date's year, not the year initially selected on the calendar. Construct civil dates with `ParseDate`, `NewDate(year, time.January, 1)` or `DateFrom(timeValue)`. `DateFrom` keeps the year, month and day in the time's own location, then discards its time of day and timezone.

### Determining if today is a holiday

```
yes, err := calendar.IsTodayHoliday()
```

Today and the current year use the local system clock. Use an explicit `Date` with `IsHoliday` or `UpcomingFrom` when your application controls the clock.

### Getting upcoming holidays

```
items, err := calendar.Upcoming(3)
items, err = calendar.UpcomingFrom(day, 3)
```

These methods include holidays on the starting date and continue into subsequent years. Separate holidays sharing a date remain separate. A country calculation error is returned immediately, rather than skipping unsupported years. Count must be positive. If there are not enough holidays before year 10000, the result is `ErrInsufficientHolidays`.

### Getting long weekends

```
germany, err := holidays.For("de", 2024)
weekends, err := germany.LongWeekends(4)
weekends, err = germany.LongWeekends(3)

for _, weekend := range weekends {
    fmt.Println(weekend.StartDate, weekend.EndDate, weekend.DayCount)
    fmt.Println(weekend.Holidays)
}
```

Like PHP, this groups neighboring holidays whose separation is at most the supplied minimum. A group needs at least two holidays and an inclusive span of at least that many days. It does not fill in Saturdays or Sundays and does not promise that every intervening day is a non-working day. The minimum must be positive.

### Getting the name of a holiday

```
name, err := calendar.Name(day)
```

Returns the first holiday's name when several share a date, or an empty string when there is no holiday.

### Determining whether a country is supported

```
holidays.Has("be")      // true
holidays.Has("unknown") // false
holidays.Countries()    // sorted country codes, including el
```

### Holiday types

Available types are `National`, `Regional`, `Religious`, `Observed` and `Bank`. Pass one or more types to `Get`, `InRange` or `Between` to filter results:

```
items, err := calendar.Get(holidays.National, holidays.Observed)
items, err = calendar.InRange("2024", "2025", holidays.Regional)
```

### Errors and concurrency

Errors can be checked with `errors.Is`. The exported sentinels are `ErrInvalidCountry`, `ErrInvalidRegion`, `ErrUnsupportedYear`, `ErrInvalidDate`, `ErrInvalidCount` and `ErrInsufficientHolidays`. Custom provider errors propagate unchanged.

Built-in calendars can be queried concurrently. `Locale` and `Region` return configured copies and results do not expose mutable shared slices. A custom provider is responsible for its own concurrency safety. Construct a calendar with `For` or `New` before querying it.

### Supported countries

The registry matches the [PHP source](https://github.com/spatie/holidays/blob/0fd2962c755d433a698e2a1bec9b76f3e756ebc5/src/CountryRegistry.php). Country rule files live at the module root. Contributions adding or correcting countries are welcome.

Saudi Arabia (`sa`) supports 2020–2037 and returns statutory private-sector holidays under Article 24 of the Saudi Labor Law's implementing regulations. Eid dates follow Umm al-Qura. Eid al-Fitr leave begins the day after 29 Ramadan, which may be before 1 Shawwal. Public-sector and banking periods and employer-specific compensatory days are not included.

Taiwan (`tw`) follows the DGPA government-office calendar for 2020–2027, including compensatory and adjusted days off as `Observed`. Ordinary weekends and make-up working Saturdays are not listed. Holidays sharing a date are returned separately. This is not a private-sector employment calendar. Labor Day was already a workers' holiday before it became a government-office holiday in 2026.

Outside 2020–2027, Taiwan retains the PHP package's legacy calculation. It returns New Year's Day, Peace Memorial Day, Children's Day, National Day, the first three days of Lunar New Year, Dragon Boat Festival and Mid-Autumn Festival. Those years are incomplete official calendars.

Nepal preserves PHP's published tables for 2024 and 2025. Other years return only International Labor Day and Christmas. Other lookup-backed countries return errors when their data runs out. Country support does not promise complete official coverage for every historical or future year.

The port preserves PHP's country rules, including historical quirks. Mexico's variable dates retain the previous civil day produced by PHP's UTC-to-Mexico-City conversion at midnight. Turkmenistan chooses its Hijri year from January 1, without PHP's dependence on the wall-clock time of the calculation. See [testing](testing) for the pinned source and reproducible parity checks.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
