NAME

DateTime::Event::Easter - Returns Easter events for DateTime objects

SYNOPSIS

  use DateTime::Event::Easter;
  
  $dt = DateTime->new( year   => 2002,
                       month  =>    3,
                       day    =>   31,
                     );
  
  
  $easter_sunday = DateTime::Event::Easter->new();

  $previous_easter_sunday = $easter_sunday->previous($dt);
  # Sun, 15 Apr 2001 00:00:00 UTC
  
  $following_easter_sunday = $easter_sunday->following($dt);
  # Sun, 20 Apr 2003 00:00:00 UTC
  
  $closest_easter_sunday = $easter_sunday->closest($dt);
  # Sun, 31 Mar 2002 00:00:00 UTC
  
  $is_easter_sunday = $easter_sunday->is($dt);
  # 1
  
  $palm_sunday = DateTime::Event::Easter->new(day=>'Palm Sunday');


  $dt2 = DateTime->new( year   => 2006,
                        month  =>    4,
                        day    =>   30,
                      );
  
  $set  = $palm_sunday->as_set (from => $dt, to => $dt2, inclusive => 1);
  @list = $palm_sunday->as_list(from => $dt, to => $dt2, inclusive => 1);
  # Sun, 13 Apr 2003 00:00:00 UTC
  # Sun, 04 Apr 2004 00:00:00 UTC
  # Sun, 20 Mar 2005 00:00:00 UTC
  # Sun, 09 Apr 2006 00:00:00 UTC
  
  $datetime_set = $palm_sunday->as_set;
  # A set of every Palm Sunday ever. See C<DateTime::Set> for more information.

DESCRIPTION

The DateTime::Event::Easter module returns Easter events for DateTime objects. From a given datetime, it can tell you the previous, the following and the closest Easter event. The 'is' method will tell you if the given DateTime is an Easter Event.

Easter Events can be Fat Tuesday, Ash Wednesday, Palm Sunday, Maundy Thursday, Good Friday, Black Saturday, Easter Sunday, Ascension, Pentecost and Trinity Sunday. If that's not enough, the module will also accept an offset so you can get the date for Quasimodo (the next sunday after Easter Sunday) by passing 7.

BACKGROUND

Easter Sunday is the Sunday following the first full moon on or following the Official Vernal Equinox. The Official Vernal Equinox is March 21st. Easter Sunday is never on the full moon. Thus the earliest Easter can be is March 22nd.

In the orthodox world, although they now use the Gregorian Calendar rather than the Julian, they still take the first full moon on or after the Julian March 21st. As the Julian calendar is slowly getting further and further out of sync with the Gregorian, the first full moon after this date can be a completely different one than for the western Easter. This is why the Orthodox churches celebrate Easter later than western churches.

CONSTRUCTOR

This class accepts the following options to its 'new' constructor:

  • easter => ([western]|eastern)

    DateTime::Event::Easter understands two calculations for Easter. For simplicity we've called them 'western' and 'eastern'.

    Western Easter is the day celebrated by the Catholic and Protestant churches. It falls on the first Sunday after the first Full Moon on or after March 21st.

    Eastern Easter, as celebrated by the Eastern Orthodox Churches similarly falls on the first Sunday after the first Full Moon on or after March 21st. However Eastern Easter uses March 21st in the Julian Calendar.

    By default this module uses the Western Easter. Even if you pass a Julian DateTime to the module, you'll get back Western Easter unless you specifically ask for Eastern.

    If this parameter is not supplied, the western Easter will be used.

  • day => ([Easter Sunday]|Palm Sunday|Maundy Thursday|Good Friday|Black Saturday|Fat Tuesday|Ash Wednesday|Ascension|Pentecost|Trinity Sunday|n)

    When constructed with a day parameter, the method can return associated Easter days other than Easter Sunday. The constructor also allows an integer to be passed here as an offset. For example, Maundy Thursday is the same as an offset of -3 (Three days before Easter Sunday) The numeric offset must be in the -80 .. +250 interval.

    When constructed without a day parameter, the method uses the date for Easter Sunday (which is the churches' official day for 'Easter', think of it a 'Easter Day' if you want)

    This parameter also allows the following abreviations: day => ([Sunday]|Palm|Thursday|Friday|Saturday|Fat|Ash|Ascension|Pentecost|Trinity)

  • as => ([point]|span)

    By default, all returns are single points in time. Namely they are the moment of midnight for the day in question. If you want Easter 2003 then you actually get back midnight of April 20th 2003. If you specify as => 'span' in your constructor, you'll now receive 24 hour spans rather than moments (or 'points'). See also the as_span and as_point methods below

METHODS

For all these methods, unless otherwise noted, $dt is a plain vanila DateTime object or a DateTime object from any DateTime::Calendar module that can handle calls to from_object and utc_rd_values (which should be all of them, but there's nothing stopping someone making a bad egg).

This class offers the following methods.

  • following($dt)

    Returns the DateTime object for the Easter Event after $dt. This will not return $dt.

  • previous($dt)

    Returns the DateTime object for the Easter Event before $dt. This will not return $dt.

  • closest($dt)

    Returns the DateTime object for the Easter Event closest to $dt. This will return midnight of $dt if $dt is the Easter Event.

  • is($dt)

    Return positive (1) if $dt is the Easter Event, otherwise returns false (0)

  • as_list(from => $dt, to => $dt2, inclusive => ([0]|1))

    Returns a list of Easter Events between to and from.

    If the optional inclusive parameter is true (non-zero), the to and from dates will be included if they are the Easter Event.

    If you do not include an inclusive parameter, we assume you do not want to include these dates (the same behaviour as supplying a false value)

  • as_set()

    Returns a DateTime::Set of Easter Events.

    In the past this method used the same syntax as 'as_list' above. However we now allow both the above syntax as well as the full options allowable when creating sets with DateTime::Set. This means you can call $datetime_set = $palm_sunday->as_set; and it will return a DateTime::Set of all Palm Sundays. See DateTime::Set for more information.

  • as_span()

    This method switches output to spans rather than points. See the 'as' attribute of the constructor for more information. The method returns the object for easy chaining.

  • as_point()

    This method switches output to points rather than spans. See the 'as' attribute of the constructor for more information. The method returns the object for easy chaining.

EXPORTS

This class does not export any methods by default, however the following exports are supported.

  • easter($year)

    Given a Gregorian year, this method will return a DateTime object for Western Easter Sunday in that year.

BUGS AND PROBLEMS FOR SPANS

Inclusion and exclusion of <from> and to dates in lists and sets

If you build a list or a set of spans and if the from or to limits coincide with the requested Easter event, the result may be different from what you expect. For example, you ask for Easter sundays between 2017-04-16T21:43:00 and 2020-04-12T12:34:00.

The inclusive list or set will be:

  2017-04-16T00:00:00 to 2017-04-16T23:59:59
  2018-04-01T00:00:00 to 2018-04-01T23:59:59
  2019-04-21T00:00:00 to 2019-04-21T23:59:59
  2020-04-12T00:00:00 to 2020-04-12T23:59:59

and not:

  2017-04-16T21:43:00 to 2017-04-16T23:59:59
  2018-04-01T00:00:00 to 2018-04-01T23:59:59
  2019-04-21T00:00:00 to 2019-04-21T23:59:59
  2020-04-12T00:00:00 to 2020-04-12T12:34:00

The exclusive list or set will be:

  2018-04-01T00:00:00 to 2018-04-01T23:59:59
  2019-04-21T00:00:00 to 2019-04-21T23:59:59

and not:

  2017-04-16T21:43:01 to 2017-04-16T23:59:59
  2018-04-01T00:00:00 to 2018-04-01T23:59:59
  2019-04-21T00:00:00 to 2019-04-21T23:59:59
  2020-04-12T00:00:00 to 2020-04-12T12:35:59

Remarks and patches welcome.

Note for pedants: the hour 21:43:01 should actually be 21 hours, 43 minutes, zero seconds and 1 nanosecond. Likewise, all the times above ending with :59 include 999_999_999 nanoseconds.

Interaction of spans with timezones

It may happen that Palm sunday or Easter sunday coincide with DST "spring forward" day (for Northern countries). I have not checked what happens in this case for spans: a bit more than one day for exactly 24 hours or exactly one day which gives 23 hours? A similar question exists for DST "fall backward" day in the Southern countries.

Also, since you can use a numeric day offset up to 250, you can reach the Northern "fall backwards" and the Southern "spring forward" days, where the same problem will happen in reverse.

Building a spanset

For the moment, when building a set with the as => 'set' option, the from and to dates are required and thus the set must be a finite set.

THE SMALL PRINT

REFERENCES

SUPPORT

Support for this module, and for all DateTime modules will be given through the DateTime mailing list - datetime@perl.org.

Bugs should be reported through rt.cpan.org.

AUTHOR

Rick Measham <rickm@cpan.org>

Co-maintainer Jean Forget <jforget@cpan.org>

CREDITS

Much help from the DateTime mailing list, especially from:

Eugene van der Pijll - who pointed out flaws causing errors on gregorian years with no eastern easter (like 35000) and who came up with a patch to make the module accept any calendar's DateTime object

Dave Rolsky - who picked nits, designed DateTime itself and leads the project

Martin Hasch - who pointed out the posibility of memory leak with an early beta

Joe Orost and Andreas König - for RT tickets about the POD documentation

Frank Wiegand and Slaven Rezić - for patches fixing the POD problems

© Copyright 2003, 2004, 2015, 2019 Rick Measham and Jean Forget. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself: GNU Public License version 1 or later and Perl Artistic License.

The full text of the license can be found in the LICENSE file included with this module or at https://dev.perl.org/licenses/artistic.html and https://www.gnu.org/licenses/gpl-1.0.html.

Here is the summary of GPL:

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, see <https://www.gnu.org/licenses/> or write to the Free Software Foundation, Inc., https://fsf.org.

SEE ALSO

DateTime, DateTime::Calendar::Julian, perl(1)

https://metacpan.org/search?q=easter which gives Date::Easter, Date::Calc and Date::Pcalc

https://github.com/houseabsolute/DateTime.pm/wiki