From: vli@mpr.ca (Vincent Li)
Subject: Re: How to convert solar calendar to lunar calendar.
Organization: MPR Teltech Ltd., Burnaby, B.C., Canada
Date: Wed, 16 Sep 92 01:46:02 GMT


I think there is a program in the following ftp site which contains, among
other neat stuff, a program to convert between the lunar & solar dates and
can give you the "8 characters"

   ftphost.cac.washington.edu [128.95.112.1]
        pub/
        chinese.tar.Z - assorted programs [some programs duplicated
                        from june.cs.washington.edu]

Following is the header comment from the source:
------------------------------------------------------------
/*
LUNAR: Western Solar Calendar <-> Chinese Lunar Calendar Conversion Program
--------------------------------------------------------------------------

Following is a program to convert between the Western Solar Calendar
and the Chinese Lunar Calendar date and time.
The date range is from 1900 thru 2000.
Lunar also outputs the corresponding "sheng1 xiao1 (animal of the year),"
and the corresponding GanZhi Chinese characters ('8 characters 
sheng1 chen2 ba1 zi4').

Notice that the time is with respect to Hong Kong Standard Time or
Beijing Standard Time (120 degree East).  Be sure to subtract one hour for
"Day-light Saving Time,"  and adjust appropriately for other time zones.

After 11pm is counted as the second day (as in zi3 wei1 dou3 shu3).  
In the '4 column calculation (si4 zhu4 shen2 suan4),'
jie1 qi4 (festivals)' are used to determine
the year and month; 11pm till before 12am is considered the same day, but
hour is considered as the first hour of next day. Our 'jie1' table only 
contains the days, not down to the hours and minutes, so if the date falls on
a 'jie1' day, a warning message will be put up and you should consult a 
detailed conversion table.

Porting lunar to other system should be straight-forward, the only 
assumption is that 'long' has at least 24 bits.

This program is NOT public domain, but permission is granted for 
non-commercial use.  If you extend the date range of this program,
please let us know.  If you find or discover any smarter algorithm
than our "table" approach, we will be eager to hear from you.

Have fun.

Reference:
1. zhong1 guo2 yin1 yang2 ri4 yue4 dui4 zhao4 mo4 nian2 li4 by lin2, qi3 yuan2
2. ming4 li3 ge2 xin1 zi3 ping2 cui4 yan2  by xu2, le4 wu2

	Solar Calendar <-> Lunar Calendar with GanZhi
	
	Copyright 1988  by   Fung Fung Lee and Ricky Yeung

	This program is NOT public domain, but permission is
	granted for non-commerical use.

	Fung Fung Lee	lee@umunhum.stanford.edu
	Ricky Yeung	yeung@june.cs.washington.edu
	
	--------------------------------------------------------------------
	88.11.24	FL	Calculate Lunar Date & GanZhi from day offset
	88.11.24      	RY	Output GanZhi in PingYin
	88.11.25	FL	Fix bug in GanZhi (month) calculation
	88.11.25	FL	Complete Solar to Lunar Conversion
	88.11.25	FL	Extend Date Range from 4 to 20 years
	88.11.25	FL	Add ShengXiao (Animal)
	88.11.25	RY	Extend Date from 1950 to 2000
	88.11.28	RY	Take care long "run" month
	88.11.28	RY	Add GanZhi for time
	88.11.29	FL	Fix FromSolar() and Add gz_cycle()
	88.12.19	RY	Actually output Chinese GanZhi characters
	88.12.21	RY	Extend Date from 1924 to 2000	
	88.12.21	RY	Complete Lunar to Solar Conversion
	88.12.28	RY	Extend Date from 1900 to 2000
	88.12.30	RY	Correctly calculate the '8 characters'
				according to '4-column calculation'
				by using a 'jie1' table.
	89.09.16	RY	Fix Day2Solar
	--------------------------------------------------------------------
	
	SC - Solar Calendar
	LC - Lunar Calendar
	GZ - GanZhi (Tian1 Gan1 Di4 Zhi1)
	
	In the Chinese Lunar Calendar,
	* a "normal year" has 12 months.
	* a month has either 29 or 30 days.
	* a "leap year" has exactly one "leap month" (Run4 Yue4), which
	  has 29 or 30 days.
	* a "leap month" which follows the j-th month is called 
	  the j-th leap month.
	* the GanZhi of the j-th leap month is the same as
	  that of the j-th month.
	* the GanZhi labelling of the year, month, day and time is a memeber
	  of the Cartesian product GxGxGxG, where G = {1,2,...,60}
	  e.g. "JiaZi" is a, "YiChou" is 2, and so son.
	* the GanZhi of the j-th leap month is the same as that of the
	  j-th month.
	* Gan = (GanZhi-1) mod 10 + 1
	  Zhi = (GanZhi-1) mod 12 + 1
*/	


-- Vince

---------------------------------------
vli@mprgate.mpr.ca        |-) It works well under pressure: Another thing
                          |-] you can say about your pillow. -- Mr Boffo
Newsgroups: soc.culture.taiwan