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

@andreisena andreisena commented Dec 14, 2017

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

@kylekatarnls
Copy link
Collaborator

@kylekatarnls kylekatarnls commented Feb 22, 2018

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

@kylekatarnls kylekatarnls commented Apr 13, 2018

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

@36864
Copy link

@36864 36864 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 kylekatarnls commented Apr 13, 2018

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

@36864
Copy link

@36864 36864 commented Apr 13, 2018

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

@kylekatarnls kylekatarnls commented Apr 13, 2018

Thanks, changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.