kal

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: BSD-3-Clause Imports: 5 Imported by: 1

README

Kal GoDoc License

Package for finding public holidays, easter, notable days, equinoxes, solstices and flag flying days. Deals with dates and intervals between dates.

Online API documentation

Features and limitations

  • Provides a collection of functions for dealing with dates, intervals between dates and special days like winter solstice.
  • Provides functions for finding public holidays ("red days"), easter, notable days, equinoxes, solstices and flag flying days, for some calendars (every country may have different flag flying days).
  • Currently, public holidays and flag flying days have only been implemented for USA, Norway and Turkey, but pull requests are welcome!

Kal utility

Screenshots
en_US

en_US

nb_NO

nb_NO

tr_TR

tr_TR

Installation

With Go 1.17 or later:

go install github.com/xyproto/kal/cmd/kal@latest

General information

Documentation

Overview

Kal is a calendar package for finding public holidays ("red days"), Easter, notable days, equinoxes, solstices and flag flying days.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Describe

func Describe(cal Calendar, date time.Time) string

Describe what type of day a given date is

func EasterDay

func EasterDay(year int) time.Time

Returns the Easter day for any given year

func FlagDay

func FlagDay(cal Calendar, date time.Time) bool

Checks if a given date is a flag flying day or not

func NotableDay

func NotableDay(cal Calendar, date time.Time) bool

Checks if a given date is a notable day or not

func RedDay

func RedDay(cal Calendar, date time.Time) bool

Checks if a given date is a "red" day or not

func TwoLetterDays

func TwoLetterDays(cal Calendar, mondayFirst bool) string

Return a space separated string of the two first letters of every weekday

func WeekNum

func WeekNum(date time.Time) int

Get the week number, from 1 to 53

Types

type CachedCalendar

type CachedCalendar struct {
	// contains filtered or unexported fields
}

A CachedCalendar wraps and caches a Calendar

func NewCachedCalendar

func NewCachedCalendar(cal Calendar) CachedCalendar

Creates a new CachedCalendar that wraps and caches the given Calendar. A CachedCalendar is also a Calendar itself, since it implements the Calendar interface.

func (CachedCalendar) DayName

func (calca CachedCalendar) DayName(date time.Weekday) string

Wraps the DayName function

func (CachedCalendar) MondayFirst

func (calca CachedCalendar) MondayFirst() bool

func (CachedCalendar) MonthName

func (calca CachedCalendar) MonthName(month time.Month) string

Wraps the MonthName function

func (CachedCalendar) NormalDay

func (calca CachedCalendar) NormalDay() string

Wraps the NormalDay function

func (CachedCalendar) NotableDay

func (calca CachedCalendar) NotableDay(date time.Time) (bool, string, bool)

Wraps the NotableDay function and caches some of the results

func (CachedCalendar) NotablePeriod

func (calca CachedCalendar) NotablePeriod(date time.Time) (bool, string)

Wraps the NotablePeriod function

func (CachedCalendar) RedDay

func (calca CachedCalendar) RedDay(date time.Time) (bool, string, bool)

Wraps the RedDay function and caches some of the results

type Calendar

type Calendar interface {
	DayName(time.Weekday) string
	RedDay(time.Time) (bool, string, bool)
	NotableDay(time.Time) (bool, string, bool)
	NormalDay() string
	NotablePeriod(time.Time) (bool, string)
	MonthName(time.Month) string
	MondayFirst() bool
}

Calendar provides a common interface for calendars of all languages and locales

func NewCalendar

func NewCalendar(locCode string, cache bool) (cal Calendar, err error)

Create a new calendar based on a given language string. * * Supported strings: * nb_NO (Norwegian Bokmål) * en_US (US English) * tr_TR (Turkish) * * The calendar can be cached for faster lookups

type NorwegianCalendar

type NorwegianCalendar struct{}

func NewNorwegianCalendar

func NewNorwegianCalendar() NorwegianCalendar

Create a new Norwegian calendar

func (NorwegianCalendar) DayName

func (nc NorwegianCalendar) DayName(day time.Weekday) string

Finds the Norwegian name for a day of the week. Note that time.Weekday starts at 0 with Sunday, not Monday.

func (NorwegianCalendar) MondayFirst

func (nc NorwegianCalendar) MondayFirst() bool

func (NorwegianCalendar) MonthName

func (nc NorwegianCalendar) MonthName(month time.Month) string

Finds the Norwegian name for a given month

func (NorwegianCalendar) NormalDay

func (nc NorwegianCalendar) NormalDay() string

An ordinary day

func (NorwegianCalendar) NotableDay

func (nc NorwegianCalendar) NotableDay(date time.Time) (bool, string, bool)

Some days are not red, but special in one way or another. Checks if a given date is notable. Returns true/false if the given date is notable, a comma separated description (in case there are more than one notable event that day) and true/false depending on if it's a flag flying day or not.

func (NorwegianCalendar) NotablePeriod

func (nc NorwegianCalendar) NotablePeriod(date time.Time) (bool, string)

Checks if a given date is in a notable time range (summer holidays, for instance)

func (NorwegianCalendar) RedDay

func (nc NorwegianCalendar) RedDay(date time.Time) (bool, string, bool)

Checks if a given date is a "red day" (public holiday) in the Norwegian calendar. Returns true/false, a description and true/false for if it's a flag day. The dates will never overlap. Includes the 24th of December, even though only half the day is red.

type TRCalendar

type TRCalendar struct{}

func NewTRCalendar

func NewTRCalendar() TRCalendar

Create a new US calendar

func (TRCalendar) DayName

func (tc TRCalendar) DayName(day time.Weekday) string

Finds the TR name for a day of the week. Note that time.Weekday starts at 0 with Sunday, not Monday.

func (TRCalendar) DayNameInEnglish

func (tc TRCalendar) DayNameInEnglish(day time.Weekday) string

Finds the english name for a day of the week. Note that time.Weekday starts at 0 with Sunday, not Monday.

func (TRCalendar) MondayFirst

func (tc TRCalendar) MondayFirst() bool

func (TRCalendar) MonthName

func (tc TRCalendar) MonthName(month time.Month) string

Finds the TR name for a given month

func (TRCalendar) MonthNameInEnglish

func (tc TRCalendar) MonthNameInEnglish(month time.Month) string

Finds the english name for a given month

func (TRCalendar) NormalDay

func (tc TRCalendar) NormalDay() string

An ordinary day

func (TRCalendar) NotableDay

func (tc TRCalendar) NotableDay(date time.Time) (bool, string, bool)

Some days are not red, but special in one way or another. Checks if a given date is notable. Returns true/false if the given date is notable, a comma separated description (in case there are more than one notable event that day) and true/false depending on if it's a flag flying day or not.

func (TRCalendar) NotablePeriod

func (tc TRCalendar) NotablePeriod(date time.Time) (bool, string)

Checks if a given date is in a notable time range (summer holidays, for instance)

func (TRCalendar) RedDay

func (tc TRCalendar) RedDay(date time.Time) (bool, string, bool)

Checks if a given date is a "red day" (public holiday) in the TR calendar. Returns true/false, a description and true/false for if it's a flag day.

type USCalendar

type USCalendar struct{}

func NewUSCalendar

func NewUSCalendar() USCalendar

Create a new US calendar

func (USCalendar) DayName

func (nc USCalendar) DayName(day time.Weekday) string

Finds the US name for a day of the week. Note that time.Weekday starts at 0 with Sunday, not Monday.

func (USCalendar) MondayFirst

func (nc USCalendar) MondayFirst() bool

func (USCalendar) MonthName

func (nc USCalendar) MonthName(month time.Month) string

Finds the US name for a given month

func (USCalendar) NormalDay

func (nc USCalendar) NormalDay() string

An ordinary day

func (USCalendar) NotableDay

func (nc USCalendar) NotableDay(date time.Time) (bool, string, bool)

Some days are not red, but special in one way or another. Checks if a given date is notable. Returns true/false if the given date is notable, a comma separated description (in case there are more than one notable event that day) and true/false depending on if it's a flag flying day or not.

func (USCalendar) NotablePeriod

func (nc USCalendar) NotablePeriod(date time.Time) (bool, string)

Checks if a given date is in a notable time range (summer holidays, for instance)

func (USCalendar) RedDay

func (nc USCalendar) RedDay(date time.Time) (bool, string, bool)

Checks if a given date is a "red day" (public holiday) in the US calendar. Returns true/false, a description and true/false for if it's a flag day. The dates will never overlap.

Directories

Path Synopsis
cmd
USA
kal

Jump to

Keyboard shortcuts

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