Skip to content
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
Closed

holiday or festive days? #116

carlituxman opened this issue Apr 24, 2014 · 10 comments
Labels
documentation Rely to documentations or gh-pages branch

Comments

@carlituxman
Copy link

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
Copy link
Contributor

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

@carlituxman
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Contributor

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
Copy link
Author

great! thanks!

@moleculezz
Copy link

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
Copy link

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
Copy link
Owner

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
Copy link

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 kylekatarnls added the macro candidate Rather than new methods, this could be a macro/mixin label Feb 14, 2018
kylekatarnls added a commit to kylekatarnls/Carbon that referenced this issue Apr 13, 2018
@kylekatarnls
Copy link
Collaborator

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

@kylekatarnls kylekatarnls added documentation Rely to documentations or gh-pages branch and removed macro candidate Rather than new methods, this could be a macro/mixin labels Apr 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Rely to documentations or gh-pages branch
Projects
None yet
Development

No branches or pull requests

7 participants