Chinese.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. namespace IndexFormula.Finance
  2. {
  3. using System;
  4. public class Chinese
  5. {
  6. private static string[] Animals = new string[] { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
  7. private static string[] Gan = new string[] { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
  8. private static int[] LunarInfo = new int[] {
  9. 0x4bd8, 0x4ae0, 0xa570, 0x54d5, 0xd260, 0xd950, 0x16554, 0x56a0, 0x9ad0, 0x55d2, 0x4ae0, 0xa5b6, 0xa4d0, 0xd250, 0x1d255, 0xb540,
  10. 0xd6a0, 0xada2, 0x95b0, 0x14977, 0x4970, 0xa4b0, 0xb4b5, 0x6a50, 0x6d40, 0x1ab54, 0x2b60, 0x9570, 0x52f2, 0x4970, 0x6566, 0xd4a0,
  11. 0xea50, 0x6e95, 0x5ad0, 0x2b60, 0x186e3, 0x92e0, 0x1c8d7, 0xc950, 0xd4a0, 0x1d8a6, 0xb550, 0x56a0, 0x1a5b4, 0x25d0, 0x92d0, 0xd2b2,
  12. 0xa950, 0xb557, 0x6ca0, 0xb550, 0x15355, 0x4da0, 0xa5d0, 0x14573, 0x52d0, 0xa9a8, 0xe950, 0x6aa0, 0xaea6, 0xab50, 0x4b60, 0xaae4,
  13. 0xa570, 0x5260, 0xf263, 0xd950, 0x5b57, 0x56a0, 0x96d0, 0x4dd5, 0x4ad0, 0xa4d0, 0xd4d4, 0xd250, 0xd558, 0xb540, 0xb5a0, 0x195a6,
  14. 0x95b0, 0x49b0, 0xa974, 0xa4b0, 0xb27a, 0x6a50, 0x6d40, 0xaf46, 0xab60, 0x9570, 0x4af5, 0x4970, 0x64b0, 0x74a3, 0xea50, 0x6b58,
  15. 0x55c0, 0xab60, 0x96d5, 0x92e0, 0xc960, 0xd954, 0xd4a0, 0xda50, 0x7552, 0x56a0, 0xabb7, 0x25d0, 0x92d0, 0xcab5, 0xa950, 0xb4a0,
  16. 0xbaa4, 0xad50, 0x55d9, 0x4ba0, 0xa5b0, 0x15176, 0x52b0, 0xa930, 0x7954, 0x6aa0, 0xad50, 0x5b52, 0x4b60, 0xa6e6, 0xa4e0, 0xd260,
  17. 0xea65, 0xd530, 0x5aa0, 0x76a3, 0x96d0, 0x4bd7, 0x4ad0, 0xa4d0, 0x1d0b6, 0xd250, 0xd520, 0xdd45, 0xb5a0, 0x56d0, 0x55b2, 0x49b0,
  18. 0xa577, 0xa4b0, 0xaa50, 0x1b255, 0x6d20, 0xada0
  19. };
  20. private static string[] MonthName = new string[] { "1 月", "2 月", "3 月", "4 月", "5 月", "6 月", "7 月", "8 月", "9 月", "10 月", "11 月", "12 月" };
  21. private static int[] SolarMonth = new int[] { 0x1f, 0x1c, 0x1f, 30, 0x1f, 30, 0x1f, 0x1f, 30, 0x1f, 30, 0x1f };
  22. private static string[] SolarTerm = new string[] {
  23. "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑",
  24. "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"
  25. };
  26. private static string[] Str1 = new string[] { "日", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
  27. private static string[] Str2 = new string[] { "初", "十", "廿", "卅", " " };
  28. private static int[] TermInfo = new int[] {
  29. 0, 0x52d8, 0xa5e3, 0xf95c, 0x14d59, 0x1a206, 0x1f763, 0x24d89, 0x2a45d, 0x2fbdf, 0x353d8, 0x3ac35, 0x404af, 0x45d25, 0x4b553, 0x50d19,
  30. 0x56446, 0x5bac6, 0x61087, 0x6658a, 0x6b9db, 0x70d90, 0x760cc, 0x7b3b6
  31. };
  32. private static string[] Zhi = new string[] { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
  33. private static int LeapDays(int y)
  34. {
  35. if (LeapMonth(y) != 0)
  36. {
  37. return (((LunarInfo[y - 0x76c] & 0x10000) != 0) ? 30 : 0x1d);
  38. }
  39. return 0;
  40. }
  41. private static int LeapMonth(int y)
  42. {
  43. return (LunarInfo[y - 0x76c] & 15);
  44. }
  45. public static IndexFormula.Finance.LunarInfo Lunar(DateTime d)
  46. {
  47. IndexFormula.Finance.LunarInfo info = new IndexFormula.Finance.LunarInfo();
  48. DateTime time = new DateTime(0x76c, 1, 1);
  49. TimeSpan span = (TimeSpan) (d - time);
  50. int totalDays = (int) span.TotalDays;
  51. info.DayCyl = totalDays + 40;
  52. info.MonthCyl = 14;
  53. int num2 = 0;
  54. int y = 0x76c;
  55. while ((y < 0x802) && (totalDays > 0))
  56. {
  57. num2 = lYearDays(y);
  58. totalDays -= num2;
  59. info.MonthCyl += 12;
  60. y++;
  61. }
  62. if (totalDays < 0)
  63. {
  64. totalDays += num2;
  65. y--;
  66. info.MonthCyl -= 12;
  67. }
  68. info.Year = y;
  69. info.YearCyl = y - 0x748;
  70. int num4 = LeapMonth(y);
  71. info.IsLeap = false;
  72. y = 1;
  73. while ((y < 13) && (totalDays > 0))
  74. {
  75. if (((num4 > 0) && (y == (num4 + 1))) && !info.IsLeap)
  76. {
  77. y--;
  78. info.IsLeap = true;
  79. num2 = LeapDays(info.Year);
  80. }
  81. else
  82. {
  83. num2 = MonthDays(info.Year, y);
  84. }
  85. if (info.IsLeap && (y == (num4 + 1)))
  86. {
  87. info.IsLeap = false;
  88. }
  89. totalDays -= num2;
  90. if (!info.IsLeap)
  91. {
  92. info.MonthCyl++;
  93. }
  94. y++;
  95. }
  96. if (((totalDays == 0) && (num4 > 0)) && (y == (num4 + 1)))
  97. {
  98. if (info.IsLeap)
  99. {
  100. info.IsLeap = false;
  101. }
  102. else
  103. {
  104. info.IsLeap = true;
  105. y--;
  106. info.MonthCyl--;
  107. }
  108. }
  109. if (totalDays < 0)
  110. {
  111. totalDays += num2;
  112. y--;
  113. info.MonthCyl--;
  114. }
  115. info.Month = y - 1;
  116. info.Day = totalDays;
  117. return info;
  118. }
  119. private static int lYearDays(int y)
  120. {
  121. int num = 0x15c;
  122. for (int i = 0x8000; i > 8; i = i >> 1)
  123. {
  124. num += ((LunarInfo[y - 0x76c] & i) != 0) ? 1 : 0;
  125. }
  126. return (num + LeapDays(y));
  127. }
  128. private static int MonthDays(int y, int m)
  129. {
  130. return (((LunarInfo[y - 0x76c] & (((int) 0x10000) >> m)) != 0) ? 30 : 0x1d);
  131. }
  132. }
  133. }