Your code overcomes the problem that Dave pointed out (the $dt needs to be cloned & truncated before being passed to $sunset) in a different fashion - another nice way of doing it.
I see what you're saying about the wrong date - but it's just a matter of perspective. I had to pick which conversion was more important. Here's the output of the included eg/sunset.pl (version .04, about to go to PAUSE):
> 2003-09-26T22:30:00 (RD731484) -> 5763-06-29T22:30:00 > 2003-09-26T22:30:00 (RD731484) -> 5764-07-01T22:30:00
in the Gregorian -> Hebrew conversion above, Friday 2003/9/26 is used. Rosh HaShana started at about 7pm, so when I add the sunset feature (second line) it says that 10:30pm on friday the 26th is Tishrei 1st, 5764.
> 5763-06-29T22:30:00 (RD731484) -> 2003-09-26T22:30:00 > 5764-07-01T22:30:00 (RD731484) -> 2003-09-26T22:30:00 > 5764-07-15T22:30:00 (RD731498) -> 2003-10-10T22:30:00
Now we convert in the other direction. As you said, in the Hebrew -> Gregorian conversions adding the sunset feature makes the Hebrew day jump ahead - but that's what I want. Elul 29th (06/29) at 10:30 pm is really on the night before, and should be 2003/09/25. I take for granted that more people need to convert an english date to a Hebrew one. I'm not aware of people using the Hebrew Calendar in daily life - only in religious matters. Since the sunset feature is still in effect, setting the Hebrew day to the 14th (last line), has it turning into the 15th. If I use your code, then the English to Hebrew conversions don't come out as I want.
I always thought that Date & Time should be more separate when thinking about the Hebrew Calendar. When discussing times in my Shul, we always mention an english date and time to represent the Hebrew Date. Conceptually, the time was always 'connected' to the english date.
Just wait until I start calculating prayer times - we'll have a good long debate then :)
Steve
Flavio S. Glock wrote:
This is my version:
[...]
if( $self->{sunset} && $self->{time_zone} ) {
my $dt = DateTime->from_object( object => $self );
my $sunset = $self->{sunset}->next( $dt );
$sunset->set_time_zone( $self->{time_zone} );
if ( $sunset->day != $dt->day ) {
$self->{rd_days}--;
}
}
Here is a test:
use strict; use DateTime::Calendar::Hebrew; use DateTime::Event::Sunrise;
my $sunset = DateTime::Event::Sunrise->sunset ( # Latitude/Longitude for NYC longitude =>'-73.59', latitude =>'40.38', );
my $h = DateTime::Calendar::Hebrew->new( year => 5000, month => 5, day => 15, sunset => $sunset, time_zone => 'America/New_York' ); print $h->datetime, " ", ($h->utc_rd_values)[0],"\n";
$h->set( hour => 22 ); print $h->datetime, " ", ($h->utc_rd_values)[0],"\n";
$h->set( day => 18 ); print $h->datetime, " ", ($h->utc_rd_values)[0],"\n";
# 5000-05-15T00:00:00 452759 # 5000-05-15T22:00:00 452758 # 5000-05-18T22:00:00 452761
- Flavio S. Glock
