Bill-Gray / lunar

Basic astronomical functions
https://www.projectpluto.com/source.htm
GNU General Public License v2.0
92 stars 46 forks source link

chinese calendar calculations #17

Open finjulhich opened 2 years ago

finjulhich commented 2 years ago

Hello, I am looking to calculate these dates in the Gregorian equivalent, ie given a Gregorian year:

  1. the ninth day of the ninth lunar month
  2. the 15th day of the 8th month
  3. fifth day of the fifth month
  4. eighth day of the fourth month

How do I achieve that and which source files and .dat files do I need?

The range of interest is the years 1950 until 2200

rds,

Bill-Gray commented 2 years ago

Hmmm... you will have the chinese.dat file already; this covers several thousand years around the present.

By default, make will build the jd example program. If you run, say, ./jd 2021 dec 15, the output should say

Wed 2021 Dec 15  0:00:00.000000000000 = JD 2459563.50000000
Day of year = 349.000000000000 
Gregorian            2021 12  15
Julian               2021 12   2
Hebrew               5782  4  11
Islamic              1443  5  10
Revolutionary         230  3  25
Persian (Jalali)     1400  9  24
Greg/Jul             2021 12  15
Chinese              4658 11  12
Modern Persian       1400  9  24
New greg             2021 12  15
Delta-T = TD - UT1 = 69.3014; TD - UTC = 69.1840; UT1 - UTC = DUT1 = -0.1174
TDB - TDT = -0.587528 milliseconds   TAI-UTC = 37.000    GPS-UTC = 18.000

So 2021 Dec 15 corresponds to the 12th day of the 11th month of year 4658 of the Chinese calendar.

jd.cpp will show how all of this works. The actual underlying code is in date.cpp and date.h. Also, a warning : all the other calendars are computed algorithmically. But because of some of the complexities in the Chinese calendar, you do need to load the chinese.dat file in your program. Again, jd.cpp shows how this is done.

yangyang-studio commented 2 years ago

Hello, Mr. Bill Gray

Please deal with the email from China with my software order.

Screenshot_2022-01-02-21-15-45-17_45e686c594768066ad9911d54d96f72b

finjulhich commented 2 years ago

Hmmm... you will have the chinese.dat file already; this covers several thousand years around the present.

By default, make will build the jd example program. If you run, say, ./jd 2021 dec 15, the output should say

Wed 2021 Dec 15  0:00:00.000000000000 = JD 2459563.50000000
Day of year = 349.000000000000 
Gregorian            2021 12  15
Julian               2021 12   2
Hebrew               5782  4  11
Islamic              1443  5  10
Revolutionary         230  3  25
Persian (Jalali)     1400  9  24
Greg/Jul             2021 12  15
Chinese              4658 11  12
Modern Persian       1400  9  24
New greg             2021 12  15
Delta-T = TD - UT1 = 69.3014; TD - UTC = 69.1840; UT1 - UTC = DUT1 = -0.1174
TDB - TDT = -0.587528 milliseconds   TAI-UTC = 37.000    GPS-UTC = 18.000

So 2021 Dec 15 corresponds to the 12th day of the 11th month of year 4658 of the Chinese calendar.

jd.cpp will show how all of this works. The actual underlying code is in date.cpp and date.h. Also, a warning : all the other calendars are computed algorithmically. But because of some of the complexities in the Chinese calendar, you do need to load the chinese.dat file in your program. Again, jd.cpp shows how this is done.

In my case, I am simply interested in finding the Chinese new year for the "current" year in the Gregorian calendar. It happens to always fall between 15 Jan and 20 Feb as I've seen historically (past 20 years, I'm not interested in earlier). Having loaded chinese.dat, I look main() in jd.c get_time_from_stringl() seems overly complicated in my use case. Given the year = 2022, I will loop over all 15 Jan 2022 until 20 Feb 2022 and convert each day to year/monh/day in chinese until I read month=1 and day=1 and that is my chinese new year's day.

How do I circumvent get_time_from_stringl in this use case?