holiday

package module
v1.1.11 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 3 Imported by: 0

README

Go Reference

holiday

This is a list of holidays announced by the Cabinet Office as national holidays. This list is compared with the Cabinet Office's list once a month, and a pull-request is created when there is an update.

package main

import (
	"fmt"
	"time"

	"github.com/ikawaha/holiday"
)

func main() {
	dates := []string{"2021/07/23", "2021/10/10"}
	for _, v := range dates {
		// YYYY/MM/DD
		day, ok := holiday.IsHolidayYYYYMMDD(v)
		fmt.Printf("IsHolidayYYYYMMDD(%s)= %q, %v\n", v, day, ok)

		// time.Time
		t, err := time.Parse(holiday.DateFormat, v)
		if err != nil {
			panic(err)
		}
		day, ok = holiday.IsHoliday(t)
		fmt.Printf("IsHoliday(%s)= %q, %v\n", v, day, ok)
	}
}

Output:

IsHolidayYYYYMMDD(2021/07/23)= "スポーツの日" true
IsHoliday(2021/07/23)= "スポーツの日" true
IsHolidayYYYYMMDD(2021/10/10)= "" false
IsHoliday(2021/10/10)= "" false

MIT

Documentation

Index

Examples

Constants

View Source
const DateFormat = `2006/01/02`

DateFormat is the date format of the key of the Holidays type.

Variables

View Source
var (
	// Catalog is the list of national holidays. In the init(), holidays.json
	// will be loaded for initialization.
	Catalog = Holidays{}
)

Functions

func IsHoliday

func IsHoliday(t time.Time) (string, bool)

IsHoliday returns the name of a holiday and true if the given time is a national holiday.

Example
testdata := []string{"2021/07/23", "2021/10/10"}
for _, v := range testdata {
	t, err := time.Parse(DateFormat, v)
	if err != nil {
		panic(err)
	}
	day, ok := IsHoliday(t)
	fmt.Printf("IsHoliday(%s)= %q, %v\n", v, day, ok)
}
Output:

IsHoliday(2021/07/23)= "スポーツの日", true
IsHoliday(2021/10/10)= "", false

func IsHolidayYYYYMMDD

func IsHolidayYYYYMMDD(date string) (string, bool)

IsHolidayYYYYMMDD returns the name of a holiday and true if the given date in YYYY/MM/DD format (eg. 2006/01/02) is a national holiday.

Example
testdata := []string{"2021/07/23", "2021/10/10"}
for _, v := range testdata {
	day, ok := IsHolidayYYYYMMDD(v)
	fmt.Printf("IsHolidayYYYYMMDD(%s)= %q, %v\n", v, day, ok)
}
Output:

IsHolidayYYYYMMDD(2021/07/23)= "スポーツの日", true
IsHolidayYYYYMMDD(2021/10/10)= "", false

Types

type Holidays

type Holidays map[string]string

Holidays represents a holidays map.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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