calendar

package
v5.3.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

Init initialize the global calendar base singleton

func InitUnitTest

func InitUnitTest()

InitUnitTest initialize the global calendar base singleton in unite test mode

func ReplaceGlobals

func ReplaceGlobals(repository Repository) func()

ReplaceGlobals affect a new repository to the global repository singleton

Types

type Base

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

Base ..

func CBase

func CBase() *Base

CBase is used to access the global calendar base

func NewCalendarBase

func NewCalendarBase() *Base

NewCalendarBase creates a new calendarsBase

func (*Base) GetResolved

func (cBase *Base) GetResolved(id int64) (Calendar, bool, error)

GetResolved get calendar resolved from global CBase

func (*Base) InPeriodFromCalendarID

func (cBase *Base) InPeriodFromCalendarID(id int64, t time.Time) (bool, bool, error)

InPeriodFromCalendarID ..

func (*Base) Update

func (cBase *Base) Update()

Update Updates the calendar map (read the new calendar from database)

type Calendar

type Calendar struct {
	ID               int64    `json:"id,omitempty"`
	Name             string   `json:"name"`
	Description      string   `json:"description"`
	Timezone         string   `json:"timezone"`
	Periods          []Period `json:"periods"`
	UnionCalendarIDs []int64  `json:"unionCalendarIDs,omitempty"`
	Enabled          bool     `json:"enabled"`
}

Calendar ..

func (Calendar) ResolveCalendar

func (c Calendar) ResolveCalendar(enabledCalendars map[int64]Calendar, joinedCalendars []int64) Calendar

ResolveCalendar resolve a calendar definition dynamically and recursively with its subcalendars Resolution order : - For each sub-calendar (with respect of order)

  • Sub-calendar Periods (with respect of order)

- Calendar Periods (with respect of order)

type Graph

type Graph struct {
	Nodes    map[int64]*Node
	Visited  map[int64]bool
	RecStack map[int64]bool
}

Graph ..

type InPeriodContains

type InPeriodContains struct {
	Contains bool `json:"contains"`
}

InPeriodContains ..

type Node

type Node struct {
	ID    int64
	Nodes []*Node
}

Node ..

type Period

type Period struct {
	Included          bool              `json:"included"`
	DateTimeIntervals *dateTimeInterval `json:"dateTimeIntervals,omitempty"`
	MonthsOfYear      *monthInterval    `json:"monthsOfYear,omitempty"`
	DaysOfMonth       *dayInterval      `json:"daysOfMonth,omitempty"`
	DaysOfWeek        *dayWeekInterval  `json:"daysOfWeek,omitempty"`
	HoursOfDay        *hoursInterval    `json:"hoursOfDay,omitempty"`
}

Period of the calendars

type PeriodStatus

type PeriodStatus int

PeriodStatus indicate if the status of a date in a period

const (
	// InPeriod period status
	InPeriod PeriodStatus = iota + 1
	// OutOfPeriod period status
	OutOfPeriod
	// NoInfo period status
	NoInfo
)

func ToPeriodStatus

func ToPeriodStatus(s string) PeriodStatus

ToPeriodStatus get the PeriodStatus from is string representation

func (PeriodStatus) MarshalJSON

func (s PeriodStatus) MarshalJSON() ([]byte, error)

MarshalJSON marshals the enum as a quoted json string

func (PeriodStatus) String

func (s PeriodStatus) String() string

func (*PeriodStatus) UnmarshalJSON

func (s *PeriodStatus) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

type PostgresRepository

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

PostgresRepository is a repository containing the user groups data based on a PSQL database and implementing the repository interface

func (*PostgresRepository) Create

func (r *PostgresRepository) Create(calendar Calendar) (int64, error)

Create method used to create a Calendar

func (*PostgresRepository) Delete

func (r *PostgresRepository) Delete(id int64) error

Delete method used to delete a Calendar

func (*PostgresRepository) Get

func (r *PostgresRepository) Get(id int64) (Calendar, bool, error)

Get search and returns a Calendar from the repository by its id

func (*PostgresRepository) GetAll

func (r *PostgresRepository) GetAll() (map[int64]Calendar, error)

GetAll method used to get all Calendars

func (*PostgresRepository) GetAllModifiedFrom

func (r *PostgresRepository) GetAllModifiedFrom(from time.Time) (map[int64]Calendar, error)

GetAllModifiedFrom returns all entities that have been modified since 'from' parameter

func (*PostgresRepository) GetSituationCalendar added in v5.0.12

func (r *PostgresRepository) GetSituationCalendar(id int64) (Calendar, bool, error)

GetSituationCalendar search and returns a Calendar from the repository by the situation id

func (*PostgresRepository) Update

func (r *PostgresRepository) Update(calendar Calendar) error

Update method used to update a Calendar

type Repository

type Repository interface {
	Get(id int64) (Calendar, bool, error)
	Create(calendar Calendar) (int64, error)
	Update(calendar Calendar) error
	Delete(id int64) error
	GetAll() (map[int64]Calendar, error)
	GetAllModifiedFrom(from time.Time) (map[int64]Calendar, error)
	GetSituationCalendar(id int64) (Calendar, bool, error)
}

Repository is a storage interface which can be implemented by multiple backend (in-memory map, sql database, in-memory cache, file system, ...) It allows standard CRUD operation on calendars

func NewPostgresRepository

func NewPostgresRepository(dbClient *sqlx.DB) Repository

NewPostgresRepository returns a new instance of PostgresRepository

func R

func R() Repository

R is used to access the global repository singleton

Jump to

Keyboard shortcuts

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