Adding a new country | holidays-go | Spatie       

 SPATIE  

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

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Holidays-go](https://spatie.be/docs/holidays-go/v1)  Adding a new country

 Version   v1      

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

  Adding a new country    
- [ 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)

 Adding a new country
====================

This is a community driven package. If you find any errors, please create a pull request with the fix, or at least open an issue.

### Basic country

Implement `Provider.Holidays(year int) ([]Holiday, error)`. `ProviderFunc` adapts a function when you do not need a struct:

```
provider := holidays.ProviderFunc(func(year int) ([]holidays.Holiday, error) {
    newYear, err := holidays.NewDate(year, time.January, 1)
    if err != nil {
        return nil, err
    }
    return []holidays.Holiday{
        {Name: "New Year's Day", Date: newYear, Type: holidays.National},
        {Name: "Easter Monday", Date: holidays.Easter(year).AddDays(1), Type: holidays.Religious},
    }, nil
})

calendar, err := holidays.New(provider, 2024)
items, err := calendar.Get()
```

Omitting `Type` defaults it to `National`. Results are cloned and sorted. Your provider receives the requested year for every query, including cross-year ranges, upcoming holidays and individual date checks.

Use `Easter(year)` for Western Easter and `OrthodoxEaster(year)` for Orthodox Easter. For weekday-relative dates, use `time.Date`, `Weekday` and `AddDays` rather than parsing natural-language strings. Western Easter follows PHP's Julian rule through 1752 and Gregorian rule afterward.

### Register your country

Applications pass custom providers to `New`. No global registration is needed. A provider can wrap an existing calendar, which itself implements `Provider`:

```
belgium, err := holidays.For("be", 2024)
if err != nil {
    return err
}
provider := holidays.ProviderFunc(func(year int) ([]holidays.Holiday, error) {
    items, err := belgium.Holidays(year)
    if err != nil {
        return nil, err
    }
    companyDay, err := holidays.NewDate(year, time.June, 12)
    if err != nil {
        return nil, err
    }
    return append(items, holidays.Holiday{Name: "Company day", Date: companyDay}), nil
})
calendar, err := holidays.New(provider, 2024)
```

For a contribution to the built-in registry, add a country rule file and an entry in `countries.go`. Add locale data to `translations.json` if needed. Country rules and lookup tables remain ordinary editable Go source.

### Regional holidays

Keep custom regional settings on your provider struct or in a closure. Validate the region in your constructor, then return its national and regional holidays together:

```
region := "XX-A"
items := []holidays.Holiday{
    {Name: "Regional Day", Date: day, Type: holidays.Regional, Region: &region},
}
```

`Calendar.Region` discovers and selects built-in regions only. It does not configure an arbitrary provider. This keeps the provider's configuration under your control instead of assuming every country uses the same settings.

### Observed holidays

Return both the original holiday and its observed day when your rules require both:

```
items := []holidays.Holiday{{Name: "New Year's Day", Date: newYear}}
if newYear.Weekday() == time.Sunday {
    items = append(items, holidays.Holiday{
        Name: "New Year's Day (Observed)",
        Date: newYear.AddDays(1),
        Type: holidays.Observed,
    })
}
```

Observed policies differ by country. The PHP helpers move weekend dates to Monday, Sunday to Monday, or Christmas and Boxing Day forward two days. Express the actual policy in your provider, including collision handling where needed.

### Holiday types

Set `Holiday.Type` to `National`, `Regional`, `Religious`, `Observed` or `Bank`. A regional holiday may also set `Region` to a code pointer. Callers can filter any provider's results using `Get`, `InRange` or `Between`.

### Calendar systems

Use `LunarDate(year, month, day, Chinese)` or `LunarDate(year, month, day, Korean)` for non-leap lunar months. It uses ordinary month starts generated from ICU 76.1 for related Gregorian years 1–9999. Korean data is separate and uses Seoul rather than Shanghai. The conversion permits a day to overflow a short lunar month, like ICU's lenient parsing.

Countries using announced Islamic, Indian or Nepali holidays can keep lookup tables in the provider. Return an error wrapping `ErrUnsupportedYear` outside the supported range. Do not silently substitute an approximate religious calendar for an announced date. Expand multi-day periods with `AddDays`, retaining only days belonging to the requested Gregorian year when that is the country's policy.

### Translations

Built-in translations live in `translations.json`, grouped by country code, locale and original holiday name. Keys must match the names returned by the rules. Missing entries retain the original name.

Custom providers can keep a locale field or wrap another provider and translate its returned names. A custom provider owns its translations rather than adding mutable global data.

### Testing

Write external-package tests beside the country file. Assert independently verified names, civil dates, types and regions through the public API. Check both sides of historical changes, leap years, observed-day collisions and lookup boundaries. Test a custom provider through the queries that need it, not only by calling the provider directly.

Run `go test -race ./...`. When changing a ported rule, update the PHP-derived fixture only after reviewing the source change and its expected dates. See [testing](testing) for regeneration and provenance.

 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)
