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

Create a Carbon instance from the easter date of a year #1052

Conversation

andreisena
Copy link

Get the easter date based on the Computus calculation. See https://en.wikipedia.org/wiki/Computus

@kylekatarnls
Copy link
Collaborator

Nice! But it seems to me a bit too specific to be part of the core library. But I hope to put some day a list of custom macros, helpers and other Carbon extensions in our documentation, and this one could be relevant in this list.

@kylekatarnls kylekatarnls added the macro candidate Rather than new methods, this could be a macro/mixin label Feb 22, 2018
@kylekatarnls
Copy link
Collaborator

kylekatarnls commented Apr 13, 2018

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

@Miguel-Serejo
Copy link

Miguel-Serejo commented Apr 13, 2018

PHP offers an easter_days() function that returns the number of days from March 21st to Easter. This can easily be used with carbon to get a year's easter date:

public static function easterSunday($year){
	//returns easter date as number of days since march 21st
	//http://php.net/manual/en/function.easter-days.php
	//easter_date is an alternative but has issues with timezones and is limited to UNIX timestamp dates
	$easter = easter_days($year);
	$march21 = Carbon::createFromDate($year, 3, 21);
	return $march21->addDays($easter);
}

@kylekatarnls
Copy link
Collaborator

kylekatarnls commented Apr 13, 2018

If it fails on year>2038, I prefer to keep the current version, if not, we can update it.

@Miguel-Serejo
Copy link

easter_date() fails for year >2038. easter_days does not.
From the php docs:

This function can be used instead of easter_date() to calculate Easter for years which fall outside the range of Unix timestamps (i.e. before 1970 or after 2037).

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

Thanks, changed.

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

Successfully merging this pull request may close these issues.

None yet

3 participants