holiday

package module
v0.0.0-...-d070866 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 6 Imported by: 0

README

This go library provides access to public holidays in germany.

There is data built int for the years 2022, 2023, 2024. The library is open to add custom data.

For usages see example_test.go

Documentation

Index

Examples

Constants

View Source
const (
	BadenWuerttemberg           = "bw"
	Bayern                      = "by"
	Bavaria                     = "by"
	Berlin                      = "be"
	Brandenburg                 = "bb"
	Bremen                      = "hb"
	Hamburg                     = "hh"
	Hessen                      = "he"
	Hesse                       = "he"
	MecklenburgVorpommern       = "mv"
	MecklenburgWesternPomerania = "mv"
	Niedersachsen               = "ni"
	LowerSaxony                 = "ni"
	NordrheinWestfalen          = "nw"
	NorthrhineWestphalia        = "nw"
	RheinlandPfalz              = "rp"
	RhinelandPalatinate         = "rp"
	Saarland                    = "sl"
	Sachsen                     = "sn"
	Saxony                      = "sn"
	SachsenAnhalt               = "st"
	SaxonyAnhalt                = "st"
	SchleswigHolstein           = "sh"
	Thueringen                  = "th"
	Thuringia                   = "th"
)

abbreviations aligned to: https://www.datenportal.bmbf.de/portal/de/G122.html

View Source
const (
	Any = ""
)

Variables

This section is empty.

Functions

func IsHoliday

func IsHoliday(date time.Time, state string) bool

IsHoliday returns true if a holiday was found for the given date

Example
package main

import (
	"fmt"
	"github.com/Oppodelldog/holiday"
	"time"
)

func main() {
	var (
		date   = time.Date(2024, 12, 25, 0, 0, 0, 0, time.Local)
		result = holiday.IsHoliday(date, holiday.Any)
	)

	if result {
		fmt.Println("it is a holiday")
	} else {
		fmt.Println("sorry, no holiday")
	}

}
Output:

it is a holiday

Types

type Entry

type Entry struct {
	Date   string `json:"date"`
	Name   string `json:"name"`
	States States `json:"states,omitempty"`
}

Entry defines one holiday date.

type File

type File struct {
	Holidays []Entry `json:"holidays"`
}

File wraps holiday date entries for file serialization.

type IndexByDate

type IndexByDate map[string]Entry

IndexByDate holds Entry indexed by Entry.Date.

type Query

type Query struct {
	Index IndexByDate
}

Query allows to check for holidays

func New

func New() *Query

New returns a new Query instance with built-in holiday data.

func (Query) AddFileToIndex

func (q Query) AddFileToIndex(file string) error

AddFileToIndex adds File data from the given filepath to the actual Query index. Existing entries in the index are overwritten.

func (Query) Find

func (q Query) Find(date time.Time, state string) (Entry, bool)

Find returns a holiday and true if a holiday was found for the given parameters.

func (Query) IsHoliday

func (q Query) IsHoliday(date time.Time, state string) bool

IsHoliday returns true if a holiday was found for the given date

Example
package main

import (
	"fmt"
	"github.com/Oppodelldog/holiday"
	"time"
)

func main() {
	var (
		date   = time.Date(2024, 12, 25, 0, 0, 0, 0, time.Local)
		query  = holiday.New()
		result = query.IsHoliday(date, holiday.Any)
	)

	if result {
		fmt.Println("it is a holiday")
	} else {
		fmt.Println("sorry, no holiday")
	}

}
Output:

it is a holiday

type States

type States []string

States holds those states the holiday date is applied to.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL