aeon-php / business-hours

🕰 Find the next working day, defined business hours.
https://aeon-php.org/docs/business-hours/
MIT License
10 stars 2 forks source link

Seasonal business days #21

Open tomaszhanc opened 4 years ago

tomaszhanc commented 4 years ago

I didn't find a way to create business hours for seasonal businesses. For example summer pub is opened every year from 1st of April to last of September. Maybe, I missed something and it's already possible. Anyway, @norberttech do you think it should be a part of aeon-php/business-hours or not?

norberttech commented 4 years ago

This is exactly one of the scenarios I had in mind when working on this library and I believe it should be possible to achieve this already out of the box.

https://github.com/aeon-php/business-hours/blob/1.x/src/Aeon/Calendar/Gregorian/BusinessHours/NonBusinessDay/NonWorkingPeriod.php

Non Working Period receive TimePeriod which can be created for the current year that can be taken from Calendar. In case that's not enough, you can always create a custom implementation of https://github.com/aeon-php/business-hours/blob/1.x/src/Aeon/Calendar/Gregorian/BusinessHours/NonBusinessDay.php

In case that won't work, please share some more details and I can try to prepare some pseudo-code maybe

tomaszhanc commented 4 years ago

Making calculation for the given year are possible. I was thinking about the object which could represent a period without a year, eg: 1st of April to last of September. It means that I need a Day object without a year. I have no idea how to call it so let's call it for now as ugly as possible DayWithoutYear:

class DayWithoutYear
{
     private MonthWithoutYear $month;
     private int $day;
}

class PeriodWithoutYear
{
    private DayWithoutYear $after;
    private DayWithoutYear $before;

    public function in(Year $year) : TimePeriod { ... }
}

In my application I need to store period without the year because year will change. I'm not sure if such an object DayWithoutYear should be a part of the library or I should implement it on my own. I can imagine that I would need that in another project so it would be nice to have it somewhere to avoid copy-pasting.

norberttech commented 4 years ago

Right, if closed season is repeatable and linear to avoid boilerplate code it might make sense to add something like ClosedSeason implementation of NonBusinessDay. Any chance you could open pull request with this?

tomaszhanc commented 4 years ago

Yeah, sure. Thanks.