Date-Converter

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

1.1	27 March 2009
	Rewritten Hebrew algorithms. Previous one did not use delay days(?). Current algorithm is taken from http://calendarhome.com/converter/calendar.js
	
1.01	26 March 2009
	Call of undefined year_length_hebrew subroutine in Hebrew.pm could raise error for certain dates.

README  view on Meta::CPAN

Date::Converter - Convert dates between calendar systems

/*
	Description
*/

Date::Converter provides a method for converting the date between calendars of
different types. Current version includes converters for Alexandrian, Armenian,
Bahai, Coptic, Ethiopian, Gregorian, Hebrew, Islamic, Julian, Macedonian,
Persian, Roman, Republican, Saka, Syrian, Tamil and Zoroastrian calendars in any
combination.

/*
	Installation
*/

perl Makefile.PL
make
make test
make install

lib/Date/Converter.pm  view on Meta::CPAN

      return $ilo + i_modp($ival - $ilo, $wide);
    }
}

1;

__END__

=head1 NAME

Date::Converter - Convert dates between calendar systems

=head1 SYNOPSIS

 use Date::Converter;
 my $converter = new Date::Converter('julian', 'gregorian');
 my ($year, $month, $day) = $converter->convert(2009, 2, 23);

=head1 ABSTRACT

Date::Converter provides a method for converting the date between calendars of
different types. Current version includes converters for Alexandrian, Armenian,
Bahai, Coptic, Ethiopian, Gregorian, Hebrew, Islamic, Julian, Macedonian,
Persian, Roman, Republican, Saka, Syrian, Tamil and Zoroastrian calendars in any
combination.

=head1 DESCRIPTION

Module converts groups of three values (year, month, day) into another group of
three values belonging to different calendar. To execute the conversion, first
create an instance of a converter for the desired pair of calendars:

 my $converter = new Date::Converter('armenian', 'hebrew');
 
Then use this instance and pass three values to it:

 my ($year, $month, $day) = $converter->convert(1450, 6, 9);
 
Result is an array of corresponding values in the target calendar.

Names of the source and the destinations are case insensitive and include these:

 alexandrian
 armenian
 bahai
 coptic
 ethiopian
 gregorian
 hebrew

lib/Date/Converter.pm  view on Meta::CPAN

 julian
 macedonian
 persian
 republican
 roman
 saka
 syrian
 tamil
 zoroastrian
 
Some calendars are known under synonymical names in literature. Such as Tamil
which is also reffered as Hindu Solar.

Any conversation is performed via so called Julian Ephemeris Date (JED),
which is the fixed date somewhere far in the past. JED value is not available
via module's interface though.

Code of the converters themself is located in respective submodule, for example
Date::Converter::Syrian. Modules are loaded on demand, thus you will not
silencely load calendars that you are not going to use.

=head1 AUTHOR

Andrew Shitov, <andy@shitov.ru>

=head1 ALGORITHM SOURCE

Algorithms which are implemented in submodules are re-written from Fortran
library CALPAC made by John Burkardt. The library was issued under GNU LGPL
(L<http://people.sc.fsu.edu/~burkardt/txt/gnu_lgpl.txt>) licence.

t/reper.t  view on Meta::CPAN

	[2425848.5, 2319, 1, 11],
	[2430266.5, 2331, 2, 19],
	[2430833.5, 2332, 9, 11],
	[2431004.5, 2333, 2, 27],
	[2448698.5, 2381, 8, 21],
	[2450138.5 , 2385, 8, 1],
	[2465737.5, 2428, 4, 25],
	[2486076.5, 2484, 1, 14]
);

for my $calendar (@list) {
    my $Calendar = ucfirst $calendar;
    eval "use Date::Converter::$Calendar";

    my @data;
    eval "\@data = \@$calendar";

    for my $item (@data) {
        my $jed = $item->[0];
        my ($y, $m, $d);
        eval "(\$y, \$m, \$d) = Date::Converter::${Calendar}::jed_to_ymdf($jed)";
        
        ok($y == $item->[1] && $m == $item->[2] && $d == $item->[3], "$Calendar JED=$jed, $y ($item->[1]) / $m ($item->[2]) / $d ($item->[3])");
    }
}

t/use.t  view on Meta::CPAN

use Test::More qw(no_plan);
use strict;

# This test only checkes whether it is possible to transcode
# the date from one calendar into another.
# Real data tests with reference time points are performed
# in reper.t script.

BEGIN {
    use_ok('Date::Converter');
}

my $converter = new Date::Converter('julian', 'gregorian');
my ($year, $month, $day) = $converter->convert(2009, 2, 23);
ok(2009 == $year && 3 == $month && 8 == $day, 'Julian to Gregorian');



( run in 0.443 second using v1.01-cache-2.11-cpan-c333fce770f )