Lunar.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. #include "stdafx.h"
  2. #ifdef _DEBUG
  3. #define new DEBUG_NEW
  4. #undef THIS_FILE
  5. static char THIS_FILE[] = __FILE__;
  6. #endif
  7. struct ConvDate
  8. {
  9. int Source; // ==0 则输入日期为西历, !=0 则输入为农历
  10. int SolarYear; //输出或输入之西历年份 YYYY
  11. int SolarMonth; //西历月 MM
  12. int SolarDate; //西历日 DD
  13. int LunarYear; //输出或输入之农历年份 YYYY
  14. int LunarMonth; //农历月 负数表示闰月
  15. int LunarDate; //农历日
  16. int Weekday; //该日为星期几 (0星期日 1星期一 2星期二 3星期三 4星期四 5星期五 6星期六)
  17. int Kan; //该日天干(0甲 1乙 2丙 3丁 4戊 5己 6庚 7辛 8壬 9癸)
  18. int Chih; //该日地支(0子 1丑 2寅 3卯 4辰 5巳 6午 7未 8申 9酉 10戌 11亥)
  19. };
  20. struct tagLunarCal
  21. {
  22. char BaseDays; //西历 1 月 1 日到农历正月初一的累积日数
  23. char Intercalation; //闰月月份. 0==此年没有闰月
  24. char BaseWeekday; //此年西历 1 月 1 日为星期几再减 1
  25. char BaseKanChih; //此年西历 1 月 1 日到干支序号减 1
  26. char MonthDays[13]; //此农历年每月之大小, 0==小月(29日), 1==大月(30日)
  27. };
  28. struct tagLunarCal LunarCal[] = {
  29. { 23, 3, 2, 17, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0 }, /* 1936 */
  30. { 41, 0, 4, 23, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 },
  31. { 30, 7, 5, 28, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 },
  32. { 49, 0, 6, 33, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },
  33. { 38, 0, 0, 38, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 }, /* 1940 */
  34. { 26, 6, 2, 44, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
  35. { 45, 0, 3, 49, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
  36. { 35, 0, 4, 54, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 },
  37. { 24, 4, 5, 59, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 }, /* 1944 */
  38. { 43, 0, 0, 5, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 },
  39. { 32, 0, 1, 10, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 },
  40. { 21, 2, 2, 15, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },
  41. { 40, 0, 3, 20, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 }, /* 1948 */
  42. { 28, 7, 5, 26, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 },
  43. { 47, 0, 6, 31, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1 },
  44. { 36, 0, 0, 36, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
  45. { 26, 5, 1, 41, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 }, /* 1952 */
  46. { 44, 0, 3, 47, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1 },
  47. { 33, 0, 4, 52, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0 },
  48. { 23, 3, 5, 57, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 },
  49. { 42, 0, 6, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 }, /* 1956 */
  50. { 30, 8, 1, 8, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 },
  51. { 48, 0, 2, 13, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 },
  52. { 38, 0, 3, 18, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
  53. { 27, 6, 4, 23, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 }, /* 1960 */
  54. { 45, 0, 6, 29, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0 },
  55. { 35, 0, 0, 34, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
  56. { 24, 4, 1, 39, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 },
  57. { 43, 0, 2, 44, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 }, /* 1964 */
  58. { 32, 0, 4, 50, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 },
  59. { 20, 3, 5, 55, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 },
  60. { 39, 0, 6, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0 },
  61. { 29, 7, 0, 5, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, /* 1968 */
  62. { 47, 0, 2, 11, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 },
  63. { 36, 0, 3, 16, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 },
  64. { 26, 5, 4, 21, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1 },
  65. { 45, 0, 5, 26, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 }, /* 1972 */
  66. { 33, 0, 0, 32, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1 },
  67. { 22, 4, 1, 37, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 },
  68. { 41, 0, 2, 42, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1 },
  69. { 30, 8, 3, 47, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 }, /* 1976 */
  70. { 48, 0, 5, 53, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1 },
  71. { 37, 0, 6, 58, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 },
  72. { 27, 6, 0, 3, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 },
  73. { 46, 0, 1, 8, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0 }, /* 1980 */
  74. { 35, 0, 3, 14, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1 },
  75. { 24, 4, 4, 19, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1 },
  76. { 43, 0, 5, 24, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1 },
  77. { 32, 10, 6, 29, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1 }, /* 1984 */
  78. { 50, 0, 1, 35, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
  79. { 39, 0, 2, 40, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1 },
  80. { 28, 6, 3, 45, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0 },
  81. { 47, 0, 4, 50, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 }, /* 1988 */
  82. { 36, 0, 6, 56, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0 },
  83. { 26, 5, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1 },
  84. { 45, 0, 1, 6, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0 },
  85. { 34, 0, 2, 11, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0 }, /* 1992 */
  86. { 22, 3, 4, 17, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
  87. { 40, 0, 5, 22, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
  88. { 30, 8, 6, 27, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1 },
  89. { 49, 0, 0, 32, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1 }, /* 1996 */
  90. { 37, 0, 2, 38, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
  91. { 27, 5, 3, 43, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1 },
  92. { 46, 0, 4, 48, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 },
  93. { 35, 0, 5, 53, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 }, /* 2000 */
  94. { 23, 4, 0, 59, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 },
  95. { 42, 0, 1, 4, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 },
  96. { 31, 0, 2, 9, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
  97. { 21, 2, 3, 14, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, /* 2004 */
  98. { 39, 0, 5, 20, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 },
  99. { 28, 7, 6, 25, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 },
  100. { 48, 0, 0, 30, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 },
  101. { 37, 0, 1, 35, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 }, /* 2008 */
  102. { 25, 5, 3, 41, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },
  103. { 44, 0, 4, 46, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },
  104. { 33, 0, 5, 51, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 },
  105. { 22, 4, 6, 56, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, /* 2012 */
  106. { 40, 0, 1, 2, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
  107. { 30, 9, 2, 7, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 },
  108. { 49, 0, 3, 12, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1 },
  109. { 38, 0, 4, 17, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0 }, /* 2016 */
  110. { 27, 6, 6, 23, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 },
  111. { 46, 0, 0, 28, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0 },
  112. { 35, 0, 1, 33, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 },
  113. { 24, 4, 2, 38, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 }, /* 2020 */
  114. { 42, 0, 4, 44, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
  115. { 31, 0, 5, 49, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 },
  116. { 21, 2, 6, 54, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 },
  117. { 40, 0, 0, 59, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 }, /* 2024 */
  118. { 28, 6, 2, 5, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 },
  119. { 47, 0, 3, 10, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1 },
  120. { 36, 0, 4, 15, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 },
  121. { 25, 5, 5, 20, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 }, /* 2028 */
  122. { 43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 },
  123. { 32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0 },
  124. { 22, 3, 2, 36, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0 }};
  125. const int FIRST_YEAR = 1936; // The first year in LunarCal[]
  126. const int LAST_YEAR = FIRST_YEAR + sizeof(LunarCal)/sizeof(struct tagLunarCal) - 1;
  127. // 西历年平年每月之日数
  128. int arr_nDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  129. // 西历年每月之累积日数, 平年与闰年 第一行平年,第二行闰年
  130. int SolarDays[2][14] = {{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396 },{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 397 }};
  131. #define NO_ERROR 0
  132. const char INPUT_YEAR_ERROR = 1;
  133. const char INPUT_MONTH_ERROR = 2;
  134. const char INPUT_DAY_ERROR = 3;
  135. /*
  136. int main(int argc, char*argv[])
  137. {
  138. struct ConvDate stConvDate;
  139. printf("0. 阳历转化为阴历\n1. 阴历转化为阳历\n");
  140. scanf("%d",&stConvDate.Source);
  141. if (stConvDate.Source == 0)
  142. {
  143. printf("输入年份:");
  144. scanf("%d",&stConvDate.SolarYear);
  145. printf("\n输入月份:");
  146. scanf("%d",&stConvDate.SolarMonth);
  147. printf("\n输入日期:");
  148. scanf("%d",&stConvDate.SolarDate);
  149. }
  150. else
  151. {
  152. printf("输入年份:");
  153. scanf("%d",&stConvDate.LunarYear);
  154. printf("\n输入月份:");
  155. scanf("%d",&stConvDate.LunarMonth);
  156. printf("\n输入日期:");
  157. scanf("%d",&stConvDate.LunarDate);
  158. }
  159. switch(CalConv(&stConvDate))
  160. {
  161. case INPUT_YEAR_ERROR:
  162. printf("INPUT_YEAR_ERROR\n");
  163. break;
  164. case INPUT_MONTH_ERROR:
  165. printf("INPUT_MONTH_ERROR\n");
  166. break;
  167. case INPUT_DAY_ERROR:
  168. printf("INPUT_DAY_ERROR\n");
  169. break;
  170. default:
  171. printf("YYMMDD: %d %d %d Week:%d Kan:%d Chih:%d\n",
  172. stConvDate.LunarYear,stConvDate.LunarMonth,stConvDate.LunarDate,
  173. stConvDate.Weekday,stConvDate.Kan,stConvDate.Chih);
  174. }
  175. return 0;
  176. }*/
  177. // 求此西历年是否为闰年, 返回 0 为平年, 1 为闰年
  178. int IsLeap(int _nYear )
  179. {
  180. if ( _nYear % 400 == 0 ) return 1;
  181. else if ( _nYear % 100 == 0 ) return 0;
  182. else if ( _nYear % 4 == 0 ) return 1;
  183. else return 0;
  184. }
  185. // 西历农历转换
  186. char CalConv( struct ConvDate *_stDate )
  187. {
  188. int nIsLeap;
  189. int nMonthDay;
  190. int nSolarMonth;
  191. int nYearOffset;
  192. int im;
  193. int l1;
  194. int l2;
  195. int nDayOfYear;
  196. int i;
  197. int lm;
  198. int nKanChih;
  199. if ( _stDate->Source == 0 ) // ==0 输入阳历,否则输出阴历
  200. {
  201. if ( _stDate->SolarYear <= FIRST_YEAR || _stDate->SolarYear > LAST_YEAR ) //检查输入年份错误
  202. {
  203. return INPUT_YEAR_ERROR;
  204. }
  205. nSolarMonth = _stDate->SolarMonth - 1; //对齐数组下标
  206. if ( nSolarMonth < 0 || nSolarMonth > 11 ) //检查输入月份错误
  207. {
  208. return INPUT_MONTH_ERROR;
  209. }
  210. nIsLeap = IsLeap( _stDate->SolarYear ); //判断是否闰年 闰年为1 平年为0
  211. if ( nSolarMonth == 1 ) // 根据平年闰年计算 2月天数
  212. {
  213. nMonthDay = nIsLeap + 28; // 是闰年 2 月加一天
  214. }
  215. else //其他月份天数
  216. {
  217. nMonthDay = arr_nDays[nSolarMonth];
  218. }
  219. if ( _stDate->SolarDate < 1 || _stDate->SolarDate > nMonthDay ) // 检查输入日期是否有误
  220. {
  221. return INPUT_DAY_ERROR;
  222. }
  223. nYearOffset = _stDate->SolarYear - FIRST_YEAR; //年份在表里面的偏移,对齐数组
  224. nDayOfYear = SolarDays[nIsLeap][nSolarMonth] + _stDate->SolarDate; //每个阳历年的第几天
  225. _stDate->Weekday = ( nDayOfYear + LunarCal[nYearOffset].BaseWeekday ) % 7; //算出星期几
  226. nKanChih = nDayOfYear + LunarCal[nYearOffset].BaseKanChih; //由天干地支的基数得出
  227. _stDate->Kan = nKanChih % 10; //算天干
  228. _stDate->Chih = nKanChih % 12; //算地支
  229. if ( nDayOfYear < LunarCal[nYearOffset].BaseDays + 1 ) //过了元旦,但还没过春节
  230. {
  231. nYearOffset--;
  232. _stDate->LunarYear = _stDate->SolarYear - 1;
  233. nIsLeap = IsLeap( _stDate->LunarYear );
  234. nSolarMonth += 12;
  235. nDayOfYear = SolarDays[nIsLeap][nSolarMonth] + _stDate->SolarDate;
  236. }
  237. else //年份一致的时间
  238. {
  239. _stDate->LunarYear = _stDate->SolarYear;
  240. }
  241. l1 = LunarCal[nYearOffset].BaseDays;
  242. for ( i=0; i<13; i++ )
  243. {
  244. l2 = l1 + LunarCal[nYearOffset].MonthDays[i] + 29;
  245. if ( nDayOfYear <= l2 )
  246. break;
  247. l1 = l2;
  248. }
  249. _stDate->LunarMonth = i + 1;
  250. _stDate->LunarDate = nDayOfYear - l1;
  251. im = LunarCal[nYearOffset].Intercalation;
  252. if ( im != 0 && _stDate->LunarMonth > im )
  253. {
  254. _stDate->LunarMonth--;
  255. if ( _stDate->LunarMonth == im )
  256. _stDate->LunarMonth = -im;
  257. }
  258. if ( _stDate->LunarMonth > 12 )
  259. _stDate->LunarMonth -= 12;
  260. }
  261. else //输入阴历,输出阳历
  262. {
  263. if ( _stDate->LunarYear < FIRST_YEAR || _stDate->LunarYear >= LAST_YEAR ) //输入之年份错误
  264. {
  265. return INPUT_YEAR_ERROR;
  266. }
  267. nYearOffset = _stDate->LunarYear - FIRST_YEAR;
  268. im = LunarCal[nYearOffset].Intercalation;
  269. lm = _stDate->LunarMonth;
  270. if ( lm < 0 )
  271. {
  272. if ( lm != -im ) return INPUT_MONTH_ERROR;
  273. }
  274. else if ( lm < 1 || lm > 12 ) return INPUT_MONTH_ERROR;
  275. if ( im != 0 )
  276. {
  277. if ( lm > im ) lm++;
  278. else if ( lm == -im ) lm = im + 1;
  279. }
  280. lm--;
  281. if ( _stDate->LunarDate > LunarCal[nYearOffset].MonthDays[lm] + 29 ) return INPUT_DAY_ERROR;
  282. nDayOfYear = LunarCal[nYearOffset].BaseDays;
  283. for ( i=0; i<lm; i++ )
  284. {
  285. nDayOfYear += LunarCal[nYearOffset].MonthDays[i] + 29;
  286. }
  287. nDayOfYear += _stDate->LunarDate;
  288. nIsLeap = IsLeap( _stDate->LunarYear );
  289. for ( i=13; i>=0; i-- )
  290. {
  291. if ( nDayOfYear > SolarDays[nIsLeap][i] ) break;
  292. }
  293. _stDate->SolarDate = nDayOfYear - SolarDays[nIsLeap][i];
  294. if ( i <= 11 )
  295. {
  296. _stDate->SolarYear = _stDate->LunarYear;
  297. _stDate->SolarMonth = i + 1;
  298. }
  299. else
  300. {
  301. _stDate->SolarYear = _stDate->LunarYear + 1;
  302. _stDate->SolarMonth = i - 11;
  303. }
  304. nIsLeap = IsLeap( _stDate->SolarYear );
  305. nYearOffset = _stDate->SolarYear - FIRST_YEAR;
  306. nDayOfYear = SolarDays[nIsLeap][_stDate->SolarMonth-1] + _stDate->SolarDate;
  307. _stDate->Weekday = ( nDayOfYear + LunarCal[nYearOffset].BaseWeekday ) % 7;
  308. nKanChih = nDayOfYear + LunarCal[nYearOffset].BaseKanChih;
  309. _stDate->Kan = nKanChih % 10;
  310. _stDate->Chih = nKanChih % 12;
  311. }
  312. return NO_ERROR;
  313. }
  314. void GongToLongOld(CString &date)
  315. {
  316. if(date.GetLength()!=10)return;
  317. struct ConvDate stConvDate;
  318. stConvDate.Source=0;//公转农
  319. stConvDate.SolarYear=atoi(date.Mid (0,4));
  320. stConvDate.SolarMonth=atoi(date.Mid (5,2));
  321. stConvDate.SolarDate=atoi(date.Mid (8,2));
  322. date="2020-13-33";
  323. if(0!=CalConv(&stConvDate))return;
  324. date.Format ("%04d-%02d-%02d", stConvDate.LunarYear,stConvDate.LunarMonth,stConvDate.LunarDate );
  325. }
  326. void LongToGong(CString &date)
  327. {
  328. if(date.GetLength()!=10)return;
  329. struct ConvDate stConvDate;
  330. stConvDate.Source=1;//农转公
  331. stConvDate.LunarYear=atoi(date.Mid (0,4));
  332. stConvDate.LunarMonth=atoi(date.Mid (5,2));
  333. stConvDate.LunarDate=atoi(date.Mid (8,2));
  334. date="2020-13-33";
  335. if(0!=CalConv(&stConvDate))return;
  336. date.Format ("%04d-%02d-%02d", stConvDate.SolarYear,stConvDate.SolarMonth,stConvDate.SolarDate );
  337. }