DateTime-Calendar-Hebrew
view release on metacpan or search on metacpan
$self->day, $sep,
$self->month, $sep,
$self->year );
}
sub datetime {
my $self = shift;
return ($self->ymd('-') . "T" . $self->hms);
}
my %formats = (
'A' => sub { $_[0]->day_name },
'a' => sub { my $a = $_[0]->day_of_week_0; (qw/Sun Mon Tue Wed Thu Fri Shabbat/)[$a] },
'B' => sub { $_[0]->month_name },
'd' => sub { sprintf( '%02d', $_[0]->day) },
'D' => sub { $_[0]->strftime( '%m/%d/%Y') },
'e' => sub { sprintf( '%2d', $_[0]->day) },
'F' => sub { $_[0]->ymd('-') },
'j' => sub { sprintf('%03d', $_[0]->day_of_year) },
'H' => sub { sprintf('%02d', $_[0]->hour) },
'I' => sub { ($_[0]->hour == 12) ? '12' : sprintf('%02d', ($_[0]->hour % 12)) },
'k' => sub { sprintf('%2d', $_[0]->hour) },
'l' => sub { ($_[0]->hour == 12) ? '12' : sprintf('%2d', ($_[0]->hour % 12)) },
'M' => sub { sprintf('%02d', $_[0]->minute) },
'm' => sub { sprintf('%02d', $_[0]->month) },
'n' => sub { "\n" },
'P' => sub { ($_[0]->hour >= 12) ? "PM" : "AM" },
'p' => sub { ($_[0]->hour >= 12) ? "pm" : "am" },
'r' => sub { $_[0]->strftime( '%I:%M:%S %p') },
'R' => sub { $_[0]->strftime( '%H:%M') },
'S' => sub { sprintf('%02d', $_[0]->second) },
'T' => sub { $_[0]->strftime( '%H:%M:%S') },
't' => sub { "\t" },
'u' => sub { my $u = $_[0]->day_of_week_0; $u == 0 ? 7 : $u },
'U' => sub { my $w = $_[0]->week_number; defined $w ? sprintf('%02d', $w) : ' ' },
'w' => sub { $_[0]->day_of_week_0 },
'W' => sub { sprintf('%02d', $_[0]->week_number) },
'y' => sub { sprintf('%02d', substr($_[0]->year, -2)) },
'Y' => sub { return $_[0]->year },
'%' => sub { '%' },
);
$formats{W} = $formats{V} = $formats{U};
sub strftime {
my ($self, @r) = @_;
foreach (@r) {
s/%([%*A-Za-z])/ $formats{$1} ? $formats{$1}->($self) : $1 /ge;
return $_ unless wantarray;
}
return @r;
}
1;
__END__
=head1 NAME
DateTime::Calendar::Hebrew - Dates in the Hebrew calendar
=head1 SYNOPSIS
use DateTime::Calendar::Hebrew;
$dt = DateTime::Calendar::Hebrew->new( year => 5782,
month => 10,
day => 4 );
=head1 DESCRIPTION
C<DateTime::Calendar::Hebrew> is the implementation of the Hebrew calendar.
Read on for more details on the Hebrew calendar.
=head1 THE HEBREW (JEWISH) CALENDAR
The Hebrew/Jewish calendar is a Luni-Solar calendar. Torah Law mandates that months are Lunar. The first day of a month coincides with the new moon in Jerusalem. (In ancient times, this was determined by witnesses. Read the books in the bibliography ...
The Hebrew Calendar uses a leap-month to regulate itself to the solar seasons. There are 12 months in a regular year. Months can be 29 or 30 days long. 2 of the months (Cheshvan & Kislev) change between having 29 & 30 days, depending on the year. In ...
Now a quick note about the numbering of the months. Most people expect a new year to start with month #1. However, the Hebrew calendar has more than one new year. The year number changes in the (Northern Hemisphere) Autumn with Tishrei (month #7), bu...
Tishrei is the month in which you find the High-Holy-Days - 'Rosh HaShana' & 'Yom Kippur'.
Nissan, the Spring-new-year, commemorates the Exodus of the Ancient Israelites from Egypt. The Torah refers to months only by number, beginning with Nissan, e.g. giving the date of Yom Kippur in 'the seventh month'.
This system works for well for us, because of the leap month. If the new year is in the spring, the leap month is month 13. Otherwise, we'd have to re-number the months after a leap-month.
Every month has a set number, using this module. Here's a list:
=over 4
=item 1. Nissan
=item 2. Iyar
=item 3. Sivan
=item 4. Tammuz
=item 5. Av or Menachem-Av
=item 6. Elul
=item 7. Tishrei
=item 8. Cheshvan or Mar-Cheshvan
=item 9. Kislev
=item 10. Teves
=item 11. Shevat
=item 12. AdarI
=item 13. AdarII (only in leap years)
=back
I<** A NOTE ABOUT SPELLING **>
If you speak Hebrew, you may take issue with my spelling of Hebrew words. I'm sorry, I used the spelling closest to the way I pronounce it. You could call it "Brooklyn-Ashkenaz-Pronunciation", if you like.
Back to the calendar. A cycle of Hebrew years takes 19 years and is called a Machzor. In that cycle, years 3, 6, 8, 11, 14, 17 & 19 are leap years.
Days (and holidays) begin at sunset, see below for more info.
The calculations for the start and length of the year are based on a number of factors, including rules about what holidays can't be on what days of the week, and things like that. For more detailed information about the Hebrew Calendar and Hebrew-Ca...
=head1 SOURCES
Here are some absolutely essential books in understanding the Hebrew(Jewish) Calendar. Be forwarned - a working knowledge of Hebrew terms will help greatly:
B<The Comprehensive Hebrew Calendar by Arthur Spier. Third, Revised edition. Feldheim Publishers. ISBN 0-87306-398-8>
This book is great. Besides for a complete Jewish Calendar from 1900 to 2100, it contains a 22 page discourse on the Jewish Calendar - history, calculation method, religious observances - the works.
B<Understanding the Jewish Calendar by Rabbi Nathan Bushwick. Moznaim Publishing Corporation. ISBN 0-94011-817-3>
Another excellent book. Explains the calendar, lunation cycles, torah portions and more. This has more Astronomy than any of the others.
B<Calendrical Calculations by Edward Reingold & Nachum Dershowitz. Cambridge University Press. ISBN 0-521-77167-6 or 0-521-77752-6>
This book focuses on the math of calendar conversions. I use the first edition, which is full of examples in LISP. The second edition is supposed to include examples in other languages. It covers many different calendars - not just Hebrew. See their...
There are other books, but those are the ones I used most extensively in my Perl coding.
=head1 METHODS
=over 4
=item * new(...)
$dt = new Date::Calendar::Hebrew(
year => 5782,
month => 10,
day => 5,
);
This class method accepts parameters for each date and time component:
"year", "month", "day", "hour", "minute", "second" and "nanosecond".
"year" is required, all the rest are optional. time fields default to
'0', month/day fields to '1'. All fields except year are tested for validity:
month : 1 to 13
day : 1 to 30
hour : 0 to 23
minute/second : 0 to 59
nanosecond : 0 to 999,999,999
C<Date::Calendar::Hebrew> doesn't support timezones. It uses the floating timezone.
The days on the Hebrew calendar begin at sunset. If you want to know the Hebrew
date, accurate with regard to local sunset, see the SUNSET section below.
=item * from_object(object => $object)
This class method can be used to construct a new object from
any object that implements the C<utc_rd_values()> method. All
C<DateTime::Calendar> modules must implement this method in order to
provide cross-calendar compatibility.
=item * set(...)
$dt->set(
year => 5782,
month => 1,
day => 1,
);
This method allows you to modify the values of the object. valid
fields are "year", "month", "day", "hour", "minute", "second",
and "nanosecond" . Returns the object being modified.
Values are checked for validity just as they are in C<new()>.
=item * utc_rd_values
Returns the current UTC Rata Die days and seconds as a three element
list. This exists primarily to allow other calendar modules to create
objects based on the values provided by this object. We don't support
timezones, so this is actually the local RD.
=item * utc_rd_as_seconds
Returns the current UTC Rata Die days and seconds purely as seconds.
This is useful when you need a single number to represent a date. We
don't support timezones, so this is actually the local RD as seconds.
=item * clone
Returns a working copy of the object.
=item * now
This class method returns a C<Date::Calendar::Hebrew> object created from C<DateTime->now()>.
=item * today
This class method returns a C<Date::Calendar::Hebrew> object created from C<DateTime->today()>.
=item * year
Returns the year.
=item * month
Returns the month of the year, from 1..13.
=item * day_of_month, day, mday
Returns the day of the month, from 1..30.
=item * day_of_month_0, day_0, mday_0
Returns the day of the month, from 0..29.
=item * hour
=item * minute
=item * second
Each method returns the parameter named in the method.
=item * month_name($month);
Returns the name of the given month. Called on an object ($dt->month_name), it returns the month name for the current month.
The Hebrew months are Nissan, Iyar, Sivan, Tammuz, (Menachem)Av, Elul, Tishrei, (Mar)Cheshvan, Kislev, Teves, Shevat & Adar. Leap years have "Adar II" or Second-Adar. If you feel that the order of the months is wrong, see the README.
=item * day_of_week, wday, dow
Returns the day of the week as a number, from 1..7, with 1 being
Sunday and 7 being Saturday.
=item * day_of_week_0, wday_0, dow_0
Returns the day of the week as a number, from 0..6, with 0 being
Sunday and 6 being Saturday.
( run in 2.108 seconds using v1.01-cache-2.11-cpan-98e64b0badf )