Skip to content

Expose business calendar workday variable via a method so that hooks can use it #117

@gavingolden

Description

@gavingolden

Request

Expose the business calendar's workday array via a method.

Details

workday is currently private so custom workday function hooks are unable to reference it.

I'd like to implement a custom WorkdayFunc while still leveraging the existing workday array pattern. In this case I can't use IsWorkday in the custom hook because it would lead to an infinite loop. It's a small array so exposing it via a method with an array-copy would prevent the underlying array from being modified arbitrarily by the caller.

func (c *BusinessCalendar) GetWorkdays() [7]bool {
  clone := c.workday
  return clone
}

// ...

c := cal.NewBusinessCalendar()
c.SetWorkday(time.Sunday, true)

c.WorkdayFunc = func(date time.Time) bool {
  // Do something custom
  // ...
  return c.GetWorkdays()[date.Weekday()] // <-- here
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions