Rick Measham schreef:
> Attached is what I hope to be the last beta of the Easter Event 
> module. I've poked it with sticks like years with no Orthodox Easter 
> (35000).
> 
> I'd like to make it run faster some time, so if anyone can think of 
> better ways to do things without the Caching problem, let me know.
> 
> Sorry if the Linebreaks are Mac .. I've tried to fix it .. promise!

They are OK now.

I've included a patch which makes following() accept datetime objects in
other calendars.

    $easter = DateTime::Event::Easter->new;
    print $easter->following( DateTime::Calendar::Pataphysical->now() )
          ->strftime("%A %d %B %Y [%*]\n");

    Sunday 01 Palotin 130 [Sts Crocodiles, crocodiles]


Eugene


--- Easter_old.pm       Sun Mar 30 01:32:42 2003
+++ Easter.pm   Sun Mar 30 01:52:36 2003
@@ -53,10 +53,17 @@
 sub following {
     my $self = shift;
     my $dt = shift;
-    croak ("Dates need to be DateTime objects") unless (ref($dt) eq 'DateTime');
-    
-    if ($self->{easter} eq 'eastern') {
-        $dt = DateTime::Calendar::Julian->from_object(object=>$dt)   
+
+    my $class = ref($dt);
+    if ($self->{easter} eq 'eastern' &&
+                $class ne 'DateTime::Calendar::Julian') {
+        croak ("Dates need to be datetime objects")
+                unless ($dt->can('utc_rd_values'));
+        $dt = DateTime::Calendar::Julian->from_object(object=>$dt);
+    } elsif ($class ne 'DateTime') {
+        croak ("Dates need to be datetime objects")
+                unless ($dt->can('utc_rd_values'));
+        $dt = DateTime->from_object(object=>$dt);
     }
 
     my $easter_this_year = $self->_easter($dt->year)+$self->{offset};
@@ -65,9 +72,8 @@
         ? $easter_this_year
         : $self->_easter($dt->year+1)+$self->{offset};
 
-    return ($self->{easter} eq 'eastern') 
-       ? DateTime->from_object(object=>$easter)
-       : $easter
+    $easter = $class->from_object(object=>$easter) if (ref($easter) ne $class);
+    return $easter;
 }
 
 sub previous {
@@ -127,7 +133,7 @@
         {   from        => { type => OBJECT },
             to          => { type => OBJECT },
             inclusive   => { type => SCALAR, default=>0 },
-        }
+        })
     ;
     
     # Make sure our args are in the right order

Reply via email to