阴历问题,非常奇怪

阴历问题,非常奇怪

阴历问题,非常奇怪
谁用过阴历模块,我在写一个 Date::Holidays::CN 模块。但是阴历用 DateTime::Calendar::Chinese 总是有些对有些不对。谁能推荐一个阴历模块?

我用 DateTime::Calendar::Chinese 的时候,比如
2004/2/5 是元宵,农历一月十五号
2005/9/18 是中秋
2005/10/11 是重阳

可我只能这样能到它们的农历,非常非常奇怪的事:
my $time = timegm(0,0,0, 5, 2, 2004);
my $dt = DateTime::Calendar::Chinese->from_epoch(epoch => $time);
$dt->set_time_zone('Asia/Shanghai');
print $dt->month, $dt->day;

$time = timelocal(0,0,0, 18, 8, 2005);
$dt = DateTime::Calendar::Chinese->from_epoch(epoch => $time);
$dt->set_time_zone('Asia/Shanghai');
print $dt->month, $dt->day;

my $time = timegm(0,0,0, 5, 2, 2004);
$dt = DateTime::Calendar::Chinese->from_epoch(epoch => $time);
$dt->set_time_zone('Asia/Shanghai');
print $dt->month, $dt->day;

第一个要用 timegm 而且月必须得写 2 而不是 2-1=1
第二个非的用 timelocal
第三个要用 timegm, 月跟第一个不同,得 -1

我真是头都大了。这能活生生把我气吐血。
最后我用 from_object 搞定了。

my $dt2 = DateTime->new(
year => $year,
month => $month,
day => $day,
hour => 0,
minute => 0,
second => 0,
nanosecond => 500000000,
time_zone => 'Asia/Shanghai',
);
# ouch! the DateTime::Calendar::Chinese is a bit too slow!
my $dt = DateTime::Calendar::Chinese->from_object(object => $dt2);
return $LUNAR->{sprintf "%02d%02d", $dt->month, $dt->day};