New issue

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

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

Already on GitHub? Sign in to your account

holiday or festive days? #116

Closed
carlituxman opened this Issue Apr 24, 2014 · 10 comments

Comments

7 participants
@carlituxman

carlituxman commented Apr 24, 2014

it can be possible have some method like isWeekend but isHoliday establishing an array or by location, to know if date is on holiday?

@Anahkiasen

This comment has been minimized.

Contributor

Anahkiasen commented Apr 24, 2014

That would be incredibly complicated, do you know how many days are considered holidays all countries combined ?

@carlituxman

This comment has been minimized.

carlituxman commented Apr 24, 2014

I think, but if we would use, we can add a config array of days for example:
'Christmas' => [12,25], //to repeat festive days every year
'New Year' => [01,01],
'my festive' => [2014,05,01] //to only day timely festive

@kylekatarnls

This comment has been minimized.

Collaborator

kylekatarnls commented Apr 24, 2014

And somes holydays (like Easter) are not same dates each year.
I think you better have to do your own extension :

MyCarbon extends Carbon {
    public function isHoliday() {
        return in_array([ $this->month, $this->day ], [
            [12, 25], // Christmas
            [01, 01], // New Year
            ...
        ]);
    }
}
@Anahkiasen

This comment has been minimized.

Contributor

Anahkiasen commented Apr 24, 2014

I think what Carbon needs is a macro functionality so you can add your own feature over it. If you need to define the holidays yourself this is pretty much what this would be.

Carbon::macro('isHoliday', function ($date) {
    return in_array($date->format('Y-m-d'), [holidays]); 
});

Carbon::parse('some-date')->isHoliday();

Something like that, that would allow people to add helpers for their edge cases, what do you think @briannesbitt ?

@carlituxman

This comment has been minimized.

carlituxman commented Apr 24, 2014

great! thanks!

@carlituxman carlituxman reopened this Apr 24, 2014

@moleculezz

This comment has been minimized.

moleculezz commented May 30, 2014

There is a set of packages that is trying to solve just that.
https://github.com/Altruja/workday which makes use of https://github.com/Mayflower/libholiday

@no92

This comment has been minimized.

no92 commented Jun 22, 2014

Good luck with that, incredibly complicated to do something like that! BTW, christmas in Germany is always the 24th of December, not the 25th.

@briannesbitt

This comment has been minimized.

Owner

briannesbitt commented Aug 26, 2014

I rather this be done in a sub class than adding macro functionality. If it then becomes flushed out and useful for others (and a common issue) then we can look at pulling it in.

@rmblstrp

This comment has been minimized.

rmblstrp commented Jul 6, 2016

I created a PR which adds Carbon extensions that check to see if a given date is a business day. Custom holiday and business schedules can be provided which allow you to properly determine what the date is for next or previous number of business days.

#706

@kylekatarnls

This comment has been minimized.

Collaborator

kylekatarnls commented Apr 13, 2018

Will appear in the documentation:
gh-pages...kylekatarnls:gh-pages-1.26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment