isdayoff

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 6 Imported by: 0

README

Isdayoff

Go Version Test Coverage Go Report Card License PkgGoDev

Клиент для работы с Isdayoff API

Требования

Go 1.25+

Установка

Убедитесь, что ваш проект использует Go Modules (если он уже использует, в корне будет файл go.mod):

go mod init

Затем подключите модуль isdayoff в вашей Go программе с помощью import:

import (
    "github.com/kotopheiop/isdayoff"
)

Запустите любую из обычных команд go (build/install/test). Инструментарий Go автоматически разрешит и загрузит модуль.

Альтернативно, вы также можете явно выполнить go get для пакета:

go get -u github.com/kotopheiop/isdayoff

Пример

package main

import (
	"fmt"
	"github.com/kotopheiop/isdayoff"
)

func main() {
	dayOff := isdayoff.New()
	countryCode := isdayoff.CountryCodeKazakhstan
	pre := false
	covid := false
	day, err := dayOff.Tomorrow(isdayoff.Params{
		CountryCode: &countryCode,
		Pre:         &pre,
		Covid:       &covid,
	})    

	fmt.Println(day) // 0
}

Примечание:

  • Названия часовых поясов (TZ) должны быть взяты из IANA

Лицензия

Этот проект распространяется под лицензией MIT. См. файл LICENSE для подробностей.

Вы можете свободно использовать, изменять и распространять этот код без каких-либо ограничений.

Documentation

Index

Examples

Constants

View Source
const (
	// DayTypeWorking working day
	DayTypeWorking DayType = "0"
	// DayTypeNonWorking non working day
	DayTypeNonWorking DayType = "1"
	// DayTypeHalfHoliday half holiday
	DayTypeHalfHoliday DayType = "2"
	// DayTypeWorkingCovid working day for Covid
	DayTypeWorkingCovid DayType = "4"

	// YearTypeNotLeap leap year
	YearTypeNotLeap YearType = "0"
	// YearTypeLeap non leap year
	YearTypeLeap YearType = "1"

	// ErrorCodeWrongDate wrong date err
	ErrorCodeWrongDate ErrorCode = "100"
	// ErrorCodeNotFound not found err
	ErrorCodeNotFound ErrorCode = "101"
	// ErrorCodeInternalError internal error
	ErrorCodeInternalError ErrorCode = "199"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    ErrorCode
	Message string
	Status  int
}

APIError represents an error returned by the API

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client for requests to isdayoff.ru

func New

func New() *Client

New initiates client with default http client

func NewWithClient

func NewWithClient(client *http.Client) *Client

NewWithClient initiates client with custom http client

func (*Client) GetBy

func (c *Client) GetBy(params Params) ([]DayType, error)

GetBy Get data by particular params

Example
client := New()
month := time.January
days, err := client.GetBy(Params{
	Year:  2024,
	Month: &month,
})
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}
fmt.Printf("January 2024 has %d days\n", len(days))
Output:
January 2024 has 31 days

func (*Client) GetByPeriod

func (c *Client) GetByPeriod(date1, date2 string, params Params) ([]DayType, error)

GetByPeriod Get data for arbitrary period (date1 to date2) Maximum 366 days can be requested date1 and date2 should be in format YYYYMMDD

func (*Client) IsLeap

func (c *Client) IsLeap(year int) (bool, error)

IsLeap checks if year is leap

Example
client := New()
isLeap, err := client.IsLeap(2020)
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}
fmt.Printf("2020 is leap year: %v\n", isLeap)
Output:
2020 is leap year: true

func (*Client) Today

func (c *Client) Today(params Params) (*DayType, error)

Today get data for today by particular params

func (*Client) Tomorrow

func (c *Client) Tomorrow(params Params) (*DayType, error)

Tomorrow get data for tomorrow by particular params

type CountryCode

type CountryCode string

CountryCode type

const (
	// CountryCodeBelarus BY - Белоруссия
	CountryCodeBelarus CountryCode = "by"
	// CountryCodeKazakhstan KZ - Казахстан
	CountryCodeKazakhstan CountryCode = "kz"
	// CountryCodeRussia RU - Россия (по умолчанию)
	CountryCodeRussia CountryCode = "ru"
	// CountryCodeUkraine UA - Украина
	CountryCodeUkraine CountryCode = "ua"
	// CountryCodeUSA USA - США (расширенный код)
	CountryCodeUSA CountryCode = "us"
	// CountryCodeUzbekistan UZ - Узбекистан (расширенный код)
	CountryCodeUzbekistan CountryCode = "uz"
	// CountryCodeTurkey TR - Турция (расширенный код)
	CountryCodeTurkey CountryCode = "tr"
)

type DayType

type DayType string

DayType type

type ErrorCode

type ErrorCode string

ErrorCode type

type Params

type Params struct {
	Year        int
	Month       *time.Month
	Day         *int
	CountryCode *CountryCode
	Pre         *bool // помечать сокращённые рабочие дни цифрой 2
	Covid       *bool // помечать рабочие дни цифрой 4 (в связи с пандемией COVID-19)
	SixDayWeek  *bool // считать, что неделя шестидневная (sd)
	TZ          *string
}

Params contains various filters for request

type YearType

type YearType string

YearType type

Jump to

Keyboard shortcuts

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