calendar

package
v5.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Day is the equivalent of 24 hours
	Day = time.Duration(24) * time.Hour
)
View Source
var (
	// Default is the default standard calendar
	Default = "default"
)

Functions

func SetDefaultCalendar

func SetDefaultCalendar(name string) error

SetDefaultCalendar replace the current default calendar by another existing calendar

func UpdateCalendar

func UpdateCalendar(name string, calendar Calendar)

UpdateCalendar replace the current default calendar by another existing calendar

Types

type Calendar

type Calendar interface {
	GetName() string

	Add(time.Time, time.Duration) time.Time
	Sub(time.Time, time.Time) time.Duration
}

Calendar is an interface for every implementation of calendars It must allow : * Add a duration (which can be negative) to a time.Time (taking working days into account) * Calculate the duration between two time.Time (taking working days into account)

func GetCalendar

func GetCalendar(name string) (Calendar, bool)

GetCalendar returns a calendar by it's name

func GetDefaultCalendar

func GetDefaultCalendar() Calendar

GetDefaultCalendar returns the set default calendar

type CountryCode

type CountryCode int

CountryCode is a standard country code (for supported calendar)

const (
	FR CountryCode = iota + 1
)

List of supported country codes

type CustomCalendar

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

CustomCalendar is a standard calendar containing date entries with specific behavior

func NewCustomCalendar

func NewCustomCalendar(name string) *CustomCalendar

NewCustomCalendar returns a new calendar instance

func (*CustomCalendar) Add

func (calendar *CustomCalendar) Add(t time.Time, d time.Duration) time.Time

Add returns the time t+d, taking into account working days

func (*CustomCalendar) AddEntries

func (calendar *CustomCalendar) AddEntries(entries ...Entry)

AddEntries add a new entry in the calendar

func (*CustomCalendar) GetName

func (calendar *CustomCalendar) GetName() string

GetName returns the calendar name

func (*CustomCalendar) Sub

func (calendar *CustomCalendar) Sub(t time.Time, u time.Time) time.Duration

Sub returns the duration t-u, taking into account working days

type Entry

type Entry struct {
	ID         time.Time `json:"id"`
	WorkingDay bool      `json:"workingDay"` // Jour ouvrable
	WorkedDay  bool      `json:"workedDay"`  // Jour ouvré
}

Entry is a single day entry in a calendar

func NewEntry

func NewEntry(t time.Time, workingDay bool, workedDay bool) Entry

NewEntry returns a new calendar entry

type StandardCalendar

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

StandardCalendar is a wrapper for a standard calendar implementation (with pre-configured holidays) It only support calendar for France (FR) but can easily implements some more country code

func NewStandardCalendar

func NewStandardCalendar(name string, country CountryCode) *StandardCalendar

NewStandardCalendar returns a new instance of a standard calendar

func (*StandardCalendar) Add

func (calendar *StandardCalendar) Add(t time.Time, d time.Duration) time.Time

Add returns the time t+d, taking into account working days

func (*StandardCalendar) GetName

func (calendar *StandardCalendar) GetName() string

GetName returns calendar name

func (*StandardCalendar) Sub

func (calendar *StandardCalendar) Sub(t time.Time, u time.Time) time.Duration

Sub returns the duration t-u, taking into account working days

Jump to

Keyboard shortcuts

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