DateTime-Calendar-Hijri

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

use ExtUtils::MakeMaker;
WriteMakefile(
    NAME         => 'DateTime::Calendar::Hijri',
    VERSION_FROM => 'lib/DateTime/Calendar/Hijri.pm',
    AUTHOR       => 'Eugene van der Pijll (pijll@gmx.net)',
    ABSTRACT     => 'DateTime objects in the Hijri (Islamic) calendar',
    PREREQ_PM    => {
                     'Test::More' => 0,
                     'Date::Hijri' => 0.02,
                    },
);

README  view on Meta::CPAN

DateTime-Calendar-Hijri
=======================

This module parses Islamic dates in the Hijri calendar. This calendar
starts at the Hijrah, the flight of Mohammed to Medina in the year 622
Gregorian.

Compared to some other DateTime calendar modules,
DateTime::Calendar::Hijri has only very limited functionality. This is
because I am not very familiar with this calendar. The module is a thin
wrapper around the Date::Hijri module by Alex Pleiner.

If you are familiar with the Hijri calendar, and if you want to take
over the maintainership of this module, please mail me at the address
included in the module documentation, or contact the datetime@perl.org
mailing list.

INSTALLATION

To install this module type the following:

perl Makefile.PL
make

lib/DateTime/Calendar/Hijri.pm  view on Meta::CPAN

sub utc_rd_values {
    my ($self) = @_;
    return $self->{rd}, $self->{rd_secs}, $self->{rd_nano};
}

1;
__END__

=head1 NAME

DateTime::Calendar::Hijri - Dates in the Hijri (Islamic) calendar

=head1 SYNOPSIS

    use DateTime::Calendar::Hijri;
    $dt = DateTime::Calendar::Hijri->new( year => 1424,
                                          month => 1,
                                          day => 1);

    $year = $dt->year;      # 1424
    $month = $dt->month;    # 1
    $day = $dt->day;        # 1

    $str = $dt->datetime;   # "1424-1-1 AH"

    $dt = DateTime::Calendar::Hijri->from_object(
                                            object => $datetime_obj
                                     );

=head1 DESCRIPTION

The Hijri calendar is based on the flight of Mohammed from Mecca to
Medina in the year 622 in the Gregorian calendar. This was taken as the
start of the new calendar, which is still used in a number of Islamic
countries.

Like the Gregorian calendar, the Hijri year consists of 12 months. The
start of each month is determined by the observation of the young moon.
This means that the Hijri calendar is not predictable: it is not known
beforehand when a new month will start. Several algorithms have been
written to predict the starting days of the month, and one of them is
used by this module. The calculated dates can therefore be one or two
days off the actual dates.

=head1 METHODS

=over 4

=item * new( ... )

lib/DateTime/Calendar/Hijri.pm  view on Meta::CPAN


Returns a string representing the Hijri date.

=item * from_object( object => ... )

Creates a Hijri date from another datetime compatible object.

=item * utc_rd_values

Returns the rata die count of days. This is used to convert from a Hijri
date to another calendar

=head1 BUGS

=item *

The dates are sometimes wrong by one or two days when you convert to or
from other calendars. This can't be helped, as the Hijri calendar is
based on observations, not on an algorithm.

=item *

The functionality offered by this module is rather minimal compared to
other calendar modules within the DateTime project. This is because I am
not very familiar with the Hijri calendar, and I feel I am unable to do
it justice. If you can, and if you are willing to put some time into
improving this module, I would be glad to hand over the maintainership.
Mail me!

=back

=head1 SUPPORT

Support for this module is provided via the datetime@perl.org email
list. See http://lists.perl.org/ for more details.

t/003_convert.t  view on Meta::CPAN

use strict;
BEGIN { $^W = 1 }

use Test::More tests => 2004;
use DateTime::Calendar::Hijri;

# "calendar conversion consistency stress test"
#
# The correctness of the conversion itself is not tested, as the correct
# results are often unknown (and I would have to use the module itself
# to get the correct answers).

for (0..500) {
    my $rd = $_*2000;
    my $testdate = DateTime::Calendar::_Test->new( $rd, 60, 1e8 );
    my $hijridate = DateTime::Calendar::Hijri->from_object(
                                                object => $testdate );
    isa_ok( $hijridate, 'DateTime::Calendar::Hijri' );

    my ($rd2, $secs, $nano) = $hijridate->utc_rd_values;
    is( $rd2, $rd, "correct rd $rd" );
    is( $secs, 60, "correct secs" );
    is( $nano, 1e8, "correct nanosecs" );
}

# Package for testing calendar conversions

sub DateTime::Calendar::_Test::new {
    my $class = shift;
    my %p;
    @p{qw/rd rd_secs rd_nano/} = @_;
    bless \%p, $class;
}

sub DateTime::Calendar::_Test::utc_rd_values {
    my $self = shift;



( run in 0.677 second using v1.01-cache-2.11-cpan-5dc5da66d9d )