On 28 Jul 2004 at 12:07, Daisuke Maki wrote:
> Allan Dyer wrote:
> > Hi
> > 
> > Thanks for creating an interesting package.
> > 
> > I'm trying to use DateTime::Calendar::Chinese to calculate public holidays for 
> > Hong Kong, as illustrated by this output from a test script, included below.
> > 
> > For 2004, Chinese New Year is 22 January, and there is a leap month after the
> > second lunar month. Buddah's Birthday is the 8th day of the 4th lunar month, so
> > (taking into account the leap month) that is 26 May. My script returns 26 
> > April. Similarly, Tuen Ng is the 5th day of the 5th month, that is 22 June, but 
> > my script returns 23 May.
> > 
> > The table after "New Moons, Month starts" lists the dates of new moons, the 
> > first day of the month with leap_month => 0 and the first day of the month with
> > leap_month => 1. There is no difference between the last two columns: setting 
> > leap_month does nothing.
> 
> Well, the modules *does* look at the leap_month, but there's obviously 
> something wrong if it's not making any difference in any of the dates 
> calculated.
> 
>      my $prior_new_moon;
>      if ($d->month == $self->month && $d->leap_month == $self->leap_month) {
>          $prior_new_moon = $p;
>      } else {
>          $prior_new_moon = DateTime::Event::Lunar->new_moon_after(
>              datetime    => $p + DateTime::Duration->new(days => 1),
>              on_or_after => 1);
>      }

I don't think I really understand what this code is doing, but it occurs to me 
that to know what lunar month it is, you need to know whether there have been 
any leap months since the last lunar new year.

I don't have Calendrical Calculations, but a friend pointed me at this webpage:
http://www.chineseastrologyonline.com/clc/Default.htm
http://www.chineseastrologyonline.com/clc/LunarCalendar.htm
This seems to suggest that you can determin which lunar month it is by finding 
which Solar Centre Point (set by the solar longitude) is in the lunar month - 
and, if there isn't one, it is a leap month. 

> I unfortunately don't have my copy of Calendrical Calculations with me 
> right now so I can't double check, but I do admit there are cases where 
> my code misses the dates somehow.... If you happen to be able to pin 
> point a test case, pls let me know..

As a test case, these are the Gregorian dates of the start of the Lunar months 
during 2004, taken from a calendar available locally here in Hong Kong 
(actually printed by Symantec, but I think it is the same as all the others):
Month   Start Date      Comment
1       2004/01/22      (Chinese New Year's Day)
2       2004/02/20
Leap 2  2004/03/21
3       2004/04/19
4       2004/05/19
5       2004/06/18      (mis-printed as 12th month!)
6       2004/07/17
7       2004/08/16
8       2004/09/14
9       2004/10/14
10      2004/11/12
11      2004/12/12

> BTW
> 
> > Base:   2004-01-01 00:00:00
> > Sui:    2004-01-22 12:00:00
> > Greg:   2004-01-22 12:00:00
> >  
> > New Moons, Month starts
> > 2004-01-22 12:00:00     2004-02-20 00:00:00     2004-02-20 00:00:00
> 
> Oh shucks...

Looking a bit more at your module, just before the code snippet you provide I 
see a comment:

# XXX - I don't know why I need to do $self->month() - 2 here

I'm guessing that this -2 and the failure for the lunar new year date are 
related.

Regards
Allan

> --d



--------------------------------------------------------------------
 Allan Dyer, CISSP, MHKCS, DFCAE | [EMAIL PROTECTED]
 Chief Consultant                | http://www.yuikee.com.hk/
 Yui Kee Computing Ltd.         |

Reply via email to