holiday

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: MIT Imports: 15 Imported by: 0

README

China Holiday

基于colly实现的中国节假日查询的Go语言工具

Go version Gin version License

示例

package main

import (
  "fmt"
  holiday "github.com/piupuer/go-china-holiday"
)

func main() {
  // 初始化实例
  h, err := holiday.New(&holiday.Config{
    // 存储至本地文件, 减少每次从线上获取
    Filename: "holiday-data",
  })
  if err != nil {
    panic(err)
  }
  b, err := h.Check("2021-01-01")
  if err != nil {
    panic(err)
  }
  // 检查指定日期是否是法定节假日
  fmt.Printf("2021-01-01是否节假日: %v\n", b)
  
  // 列举2021年所有节假日
  holidays, workdays, err := h.List(2021)
  if err != nil {
    panic(err)
  }
  fmt.Println("2021年:\n", "节假日", holidays, "\n调休日(需要上班)", workdays)
  
  // 查询指定时间范围节假日(注意:将来的节假日需等gov.cn发布)
  holidays, workdays, err = h.Range("2020-04-01", "2021-12-01")
  if err != nil {
    panic(err)
  }
  fmt.Println("2020-04-01至2021-12-01:\n", "节假日", holidays, "\n调休日(需要上班)", workdays)
}

互动交流

与作者对话

加群一起学习一起进步

QQ群:943724601

QQ群

MIT License

Copyright (c) 2021 piupuer

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChinaHoliday

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

func New

func New(config *Config) (*ChinaHoliday, error)

创建实例

func (*ChinaHoliday) Check

func (s *ChinaHoliday) Check(date string) (bool, error)

检查某个日期是否是节假日(支持yyyy-MM-dd)

func (*ChinaHoliday) List

func (s *ChinaHoliday) List(year int) ([]string, []string, error)

获取某一年节假日数目(周末除外)

func (*ChinaHoliday) Range

func (s *ChinaHoliday) Range(startDate, endDate string) ([]string, []string, error)

获取指定日期之间有多少节假日

type Config added in v1.0.5

type Config struct {
	Filename string // 数据文件名
}

参数

Jump to

Keyboard shortcuts

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