Documentation
¶
Overview ¶
Package goholiday provides Package ome simple calculation functions. These are functions to calculate business days.
Index ¶
- func BusinessDaysAfter(t time.Time, bds int) time.Timedeprecated
- func BusinessDaysBefore(t time.Time, bds int) time.Timedeprecated
- func IsBusinessDay(t time.Time) booldeprecated
- func IsHoliday(t time.Time) booldeprecated
- func IsNationalHoliday(t time.Time) booldeprecated
- func SetUniqueHolidays(ts []time.Time)deprecated
- type Goholiday
- func (g *Goholiday) BusinessDaysAfter(t time.Time, bds int) time.Time
- func (g *Goholiday) BusinessDaysBefore(t time.Time, bds int) time.Time
- func (g *Goholiday) IsBusinessDay(t time.Time) bool
- func (g *Goholiday) IsHoliday(t time.Time) bool
- func (g *Goholiday) IsNationalHoliday(t time.Time) bool
- func (g *Goholiday) SetUniqueHolidays(ts []time.Time)
- type Schedule
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBusinessDay
deprecated
func IsNationalHoliday
deprecated
func SetUniqueHolidays
deprecated
Types ¶
type Goholiday ¶ added in v0.1.8
type Goholiday struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "fmt" "time" "github.com/yut-kt/goholiday/nholidays" "github.com/yut-kt/goholiday/nholidays/uk" "github.com/yut-kt/goholiday" "github.com/yut-kt/goholiday/nholidays/jp" ) func main() { // Japan Schedule ghj := goholiday.New(jp.New()) fmt.Println(ghj.IsNationalHoliday(time.Date(2022, 1, 1, 0, 0, 0, 0, time.Local))) // England Schedule ghe := goholiday.New(uk.NewEngland()) fmt.Println(ghe.IsNationalHoliday(time.Date(2022, 1, 1, 0, 0, 0, 0, time.Local))) // Original Schedule mySchedule := nholidays.New( map[time.Weekday]struct{}{}, map[string]string{"2022-05-01": "my holiday"}, ) ghMine := goholiday.New(mySchedule) fmt.Println(ghMine.IsNationalHoliday(time.Date(2022, 5, 1, 0, 0, 0, 0, time.Local))) }
Output: true true true
func New ¶ added in v0.1.8
Example ¶
package main import ( "fmt" "github.com/yut-kt/goholiday" "github.com/yut-kt/goholiday/nholidays/jp" ) func main() { gh := goholiday.New(jp.New()) fmt.Printf("%T", gh) }
Output: *goholiday.Goholiday
func (*Goholiday) BusinessDaysAfter ¶ added in v0.1.8
Example ¶
package main import ( "fmt" "time" "github.com/yut-kt/goholiday" "github.com/yut-kt/goholiday/nholidays/jp" ) func main() { cases := []struct { date time.Time days int expect time.Time }{ { date: time.Date(2017, 10, 5, 0, 0, 0, 0, time.Local), days: 1, expect: time.Date(2017, 10, 6, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 5, 0, 0, 0, 0, time.Local), days: 2, expect: time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 6, 0, 0, 0, 0, time.Local), days: 1, expect: time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 6, 0, 0, 0, 0, time.Local), days: 2, expect: time.Date(2017, 10, 11, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 7, 0, 0, 0, 0, time.Local), days: 1, expect: time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 9, 0, 0, 0, 0, time.Local), days: 1, expect: time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), }, } gh := goholiday.New(jp.New()) for _, c := range cases { fmt.Println(gh.BusinessDaysAfter(c.date, c.days).Format("2006-01-02") == c.expect.Format("2006-01-02")) } }
Output: true true true true true true
func (*Goholiday) BusinessDaysBefore ¶ added in v0.1.8
Example ¶
package main import ( "fmt" "time" "github.com/yut-kt/goholiday" "github.com/yut-kt/goholiday/nholidays/jp" ) func main() { cases := []struct { date time.Time days int expect time.Time }{ { date: time.Date(2017, 10, 11, 0, 0, 0, 0, time.Local), days: 1, expect: time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 11, 0, 0, 0, 0, time.Local), days: 2, expect: time.Date(2017, 10, 6, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), days: 1, expect: time.Date(2017, 10, 6, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), days: 2, expect: time.Date(2017, 10, 5, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 9, 0, 0, 0, 0, time.Local), days: 1, expect: time.Date(2017, 10, 6, 0, 0, 0, 0, time.Local), }, { date: time.Date(2017, 10, 8, 0, 0, 0, 0, time.Local), days: 1, expect: time.Date(2017, 10, 6, 0, 0, 0, 0, time.Local), }, } gh := goholiday.New(jp.New()) for _, c := range cases { fmt.Println(gh.BusinessDaysBefore(c.date, c.days).Format("2006-01-02") == c.expect.Format("2006-01-02")) } }
Output: true true true true true true
func (*Goholiday) IsBusinessDay ¶ added in v0.1.8
Example ¶
package main import ( "fmt" "time" "github.com/yut-kt/goholiday" "github.com/yut-kt/goholiday/nholidays/jp" ) func main() { targets := []time.Time{ // national holiday of weekday" time.Date(2017, 10, 9, 0, 0, 0, 0, time.Local), // national holiday of holiday time.Date(2017, 9, 23, 0, 0, 0, 0, time.Local), // business day time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), // Sunday time.Date(2017, 9, 24, 0, 0, 0, 0, time.Local), } gh := goholiday.New(jp.New()) for _, target := range targets { fmt.Println(gh.IsBusinessDay(target)) } }
Output: false false true false
func (*Goholiday) IsHoliday ¶ added in v0.1.8
Example ¶
package main import ( "fmt" "time" "github.com/yut-kt/goholiday" "github.com/yut-kt/goholiday/nholidays/jp" ) func main() { targets := []time.Time{ // national holiday of weekday" time.Date(2017, 10, 9, 0, 0, 0, 0, time.Local), // national holiday of holiday time.Date(2017, 9, 23, 0, 0, 0, 0, time.Local), // business day time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), // Sunday time.Date(2017, 9, 24, 0, 0, 0, 0, time.Local), } gh := goholiday.New(jp.New()) for _, target := range targets { fmt.Println(gh.IsHoliday(target)) } }
Output: true true false true
func (*Goholiday) IsNationalHoliday ¶ added in v0.1.8
Example ¶
package main import ( "fmt" "time" "github.com/yut-kt/goholiday" "github.com/yut-kt/goholiday/nholidays/jp" ) func main() { targets := []time.Time{ // national holiday of weekday" time.Date(2017, 10, 9, 0, 0, 0, 0, time.Local), // national holiday of holiday time.Date(2017, 9, 23, 0, 0, 0, 0, time.Local), // business day time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local), // Sunday time.Date(2017, 9, 24, 0, 0, 0, 0, time.Local), } gh := goholiday.New(jp.New()) for _, target := range targets { fmt.Println(gh.IsNationalHoliday(target)) } }
Output: true true false false
func (*Goholiday) SetUniqueHolidays ¶ added in v0.1.8
Example ¶
package main import ( "fmt" "time" "github.com/yut-kt/goholiday" "github.com/yut-kt/goholiday/nholidays/jp" ) func main() { gh := goholiday.New(jp.New()) gh.SetUniqueHolidays([]time.Time{time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local)}) date := time.Date(2017, 10, 10, 0, 0, 0, 0, time.Local) fmt.Println(gh.IsHoliday(date)) fmt.Println(gh.IsBusinessDay(date)) fmt.Println(gh.IsNationalHoliday(date)) }
Output: true false false
Click to show internal directories.
Click to hide internal directories.