Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
gavingolden opened this issue Jul 14, 2023 · 0 comments

Comments

@gavingolden
Copy link

gavingolden commented Jul 14, 2023

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
}
@gavingolden gavingolden changed the title Make workday variable public so that hooks can use them Expose business calendar workday variable via a method so that hooks can use them Jul 14, 2023
@gavingolden gavingolden changed the title Expose business calendar workday variable via a method so that hooks can use them Expose business calendar workday variable via a method so that hooks can use it Jul 14, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant