Yes, that would be a bug - I'll get that one too. Now I have something more than a POD change for version .03. :) I think I'll also add in overloaded comparison operators, for what it's worth.
Flavio, do you still see a problem with the code? I think it works fine (independent of the bug below).
Steve
Dave Rolsky wrote:
On Tue, 30 Sep 2003, Steven J. Weinberger wrote:
If the RD is a value that only changes at midnight (as you noted previously), then I think my order is right. The way you're suggesting would change the RD if it's after sunset - wouldn't it? If you took a DT::Calendar::Hebrew with an incremented RD and converted it to a DateTime, then converted that DateTime to another DT::Calendar::Hebrew, wouldn't you keep jumping ahead a day, b/c each time you'd increment RD b/c it's after sunset on the day in question?
Rata Die, the way we use it in DateTime modules, counts the number of days since 0001-01-01 00:00:00 UTC, period. That means if you take a DateTime like 2001-02-23 22:00:00 UTC as a DateTime object, then convert it to a DT::C::Hebrew object, and then back, it should still represent the same UTC RD date and time, 2001-02-23 22:00:00.
In this case, I think your code is correct and Flavio is misreading it, perhaps.
However, I think you do have a bug here:
if($self->{sunset} and $self->{time_zone}) { my $DT_Event_Sunrise = $self->{sunset}; my $time_zone = $self->{time_zone}; my $DT = DateTime->from_object(object => $self); $DT->truncate(to => 'day');
my $sunset = $DT_Event_Sunrise->next($DT); $sunset->set_time_zone($time_zone);
if($sunset > $DT) { $self->{after_sunset} = 1; @{$self}{qw/year month day/} = &_from_rd($self->{rd_days} + 1); } }
You truncate the $DT var to the day, then ask for the next sunset after that $DT. Then you check if "$sunset > $DT". Well, since you just truncated $DT and asked for the _next_ sunset, it's _always_ going to be after $DT!
I think you need to do this:
my $sunset = $DT_Event_Sunrise->next( $DT->clone->truncate( to => 'day' ) );
and not truncate $DT itself.
BTW, if you want to put this code in the perl-date-time repository on SF, let me know.
-dave
/*======================= House Absolute Consulting www.houseabsolute.com =======================*/
