convertSolarLunar.js 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /**
  2. * @1900-2100区间内的公历、农历互转
  3. * @Version 1.0.3
  4. * @公历转农历:calendar.solar2lunar(1987,11,01); //[you can ignore params of prefix 0]
  5. * @农历转公历:calendar.lunar2solar(1987,09,10); //[you can ignore params of prefix 0]
  6. */
  7. /* 公历年月日转农历数据 返回json */
  8. // calendar.solar2lunar(1987,11,01);
  9. /** 农历年月日转公历年月日 **/
  10. // calendar.lunar2solar(1987,9,10);
  11. // 调用以上方法后返回类似如下object(json)具体以上就不需要解释了吧!
  12. // c开头的是公历各属性值 l开头的自然就是农历咯 gz开头的就是天干地支纪年的数据啦~
  13. // {
  14. // Animal: "兔",
  15. // IDayCn: "初十",
  16. // IMonthCn: "九月",
  17. // Term: null,
  18. // astro: "天蝎座",
  19. // cDay: 1,
  20. // cMonth: 11,
  21. // cYear: 1987,
  22. // gzDay: "甲寅",
  23. // gzMonth: "庚戌",
  24. // gzYear: "丁卯",
  25. // isLeap: false,
  26. // isTerm: false,
  27. // isToday: false,
  28. // lDay: 10,
  29. // lMonth: 9,
  30. // lYear: 1987,
  31. // nWeek: 7,
  32. // ncWeek: "星期日"
  33. // }
  34. // 该代码还有其他可以调用的方法,请自己查看代码中的详细注释
  35. const calendar = {
  36. /**
  37. * 农历1900-2100的润大小信息表
  38. * @Array Of Property
  39. * @return Hex
  40. */
  41. lunarInfo: [
  42. 0x04bd8,
  43. 0x04ae0,
  44. 0x0a570,
  45. 0x054d5,
  46. 0x0d260,
  47. 0x0d950,
  48. 0x16554,
  49. 0x056a0,
  50. 0x09ad0,
  51. 0x055d2, // 1900-1909
  52. 0x04ae0,
  53. 0x0a5b6,
  54. 0x0a4d0,
  55. 0x0d250,
  56. 0x1d255,
  57. 0x0b540,
  58. 0x0d6a0,
  59. 0x0ada2,
  60. 0x095b0,
  61. 0x14977, // 1910-1919
  62. 0x04970,
  63. 0x0a4b0,
  64. 0x0b4b5,
  65. 0x06a50,
  66. 0x06d40,
  67. 0x1ab54,
  68. 0x02b60,
  69. 0x09570,
  70. 0x052f2,
  71. 0x04970, // 1920-1929
  72. 0x06566,
  73. 0x0d4a0,
  74. 0x0ea50,
  75. 0x06e95,
  76. 0x05ad0,
  77. 0x02b60,
  78. 0x186e3,
  79. 0x092e0,
  80. 0x1c8d7,
  81. 0x0c950, // 1930-1939
  82. 0x0d4a0,
  83. 0x1d8a6,
  84. 0x0b550,
  85. 0x056a0,
  86. 0x1a5b4,
  87. 0x025d0,
  88. 0x092d0,
  89. 0x0d2b2,
  90. 0x0a950,
  91. 0x0b557, // 1940-1949
  92. 0x06ca0,
  93. 0x0b550,
  94. 0x15355,
  95. 0x04da0,
  96. 0x0a5b0,
  97. 0x14573,
  98. 0x052b0,
  99. 0x0a9a8,
  100. 0x0e950,
  101. 0x06aa0, // 1950-1959
  102. 0x0aea6,
  103. 0x0ab50,
  104. 0x04b60,
  105. 0x0aae4,
  106. 0x0a570,
  107. 0x05260,
  108. 0x0f263,
  109. 0x0d950,
  110. 0x05b57,
  111. 0x056a0, // 1960-1969
  112. 0x096d0,
  113. 0x04dd5,
  114. 0x04ad0,
  115. 0x0a4d0,
  116. 0x0d4d4,
  117. 0x0d250,
  118. 0x0d558,
  119. 0x0b540,
  120. 0x0b6a0,
  121. 0x195a6, // 1970-1979
  122. 0x095b0,
  123. 0x049b0,
  124. 0x0a974,
  125. 0x0a4b0,
  126. 0x0b27a,
  127. 0x06a50,
  128. 0x06d40,
  129. 0x0af46,
  130. 0x0ab60,
  131. 0x09570, // 1980-1989
  132. 0x04af5,
  133. 0x04970,
  134. 0x064b0,
  135. 0x074a3,
  136. 0x0ea50,
  137. 0x06b58,
  138. 0x055c0,
  139. 0x0ab60,
  140. 0x096d5,
  141. 0x092e0, // 1990-1999
  142. 0x0c960,
  143. 0x0d954,
  144. 0x0d4a0,
  145. 0x0da50,
  146. 0x07552,
  147. 0x056a0,
  148. 0x0abb7,
  149. 0x025d0,
  150. 0x092d0,
  151. 0x0cab5, // 2000-2009
  152. 0x0a950,
  153. 0x0b4a0,
  154. 0x0baa4,
  155. 0x0ad50,
  156. 0x055d9,
  157. 0x04ba0,
  158. 0x0a5b0,
  159. 0x15176,
  160. 0x052b0,
  161. 0x0a930, // 2010-2019
  162. 0x07954,
  163. 0x06aa0,
  164. 0x0ad50,
  165. 0x05b52,
  166. 0x04b60,
  167. 0x0a6e6,
  168. 0x0a4e0,
  169. 0x0d260,
  170. 0x0ea65,
  171. 0x0d530, // 2020-2029
  172. 0x05aa0,
  173. 0x076a3,
  174. 0x096d0,
  175. 0x04afb,
  176. 0x04ad0,
  177. 0x0a4d0,
  178. 0x1d0b6,
  179. 0x0d250,
  180. 0x0d520,
  181. 0x0dd45, // 2030-2039
  182. 0x0b5a0,
  183. 0x056d0,
  184. 0x055b2,
  185. 0x049b0,
  186. 0x0a577,
  187. 0x0a4b0,
  188. 0x0aa50,
  189. 0x1b255,
  190. 0x06d20,
  191. 0x0ada0, // 2040-2049
  192. /** Add By JJonline@JJonline.Cn **/
  193. 0x14b63,
  194. 0x09370,
  195. 0x049f8,
  196. 0x04970,
  197. 0x064b0,
  198. 0x168a6,
  199. 0x0ea50,
  200. 0x06b20,
  201. 0x1a6c4,
  202. 0x0aae0, // 2050-2059
  203. 0x0a2e0,
  204. 0x0d2e3,
  205. 0x0c960,
  206. 0x0d557,
  207. 0x0d4a0,
  208. 0x0da50,
  209. 0x05d55,
  210. 0x056a0,
  211. 0x0a6d0,
  212. 0x055d4, // 2060-2069
  213. 0x052d0,
  214. 0x0a9b8,
  215. 0x0a950,
  216. 0x0b4a0,
  217. 0x0b6a6,
  218. 0x0ad50,
  219. 0x055a0,
  220. 0x0aba4,
  221. 0x0a5b0,
  222. 0x052b0, // 2070-2079
  223. 0x0b273,
  224. 0x06930,
  225. 0x07337,
  226. 0x06aa0,
  227. 0x0ad50,
  228. 0x14b55,
  229. 0x04b60,
  230. 0x0a570,
  231. 0x054e4,
  232. 0x0d160, // 2080-2089
  233. 0x0e968,
  234. 0x0d520,
  235. 0x0daa0,
  236. 0x16aa6,
  237. 0x056d0,
  238. 0x04ae0,
  239. 0x0a9d4,
  240. 0x0a2d0,
  241. 0x0d150,
  242. 0x0f252, // 2090-2099
  243. 0x0d520
  244. ], // 2100
  245. /**
  246. * 公历每个月份的天数普通表
  247. * @Array Of Property
  248. * @return Number
  249. */
  250. solarMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
  251. /**
  252. * 天干地支之天干速查表
  253. * @Array Of Property trans["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"]
  254. * @return Cn string
  255. */
  256. Gan: [
  257. '\u7532',
  258. '\u4e59',
  259. '\u4e19',
  260. '\u4e01',
  261. '\u620a',
  262. '\u5df1',
  263. '\u5e9a',
  264. '\u8f9b',
  265. '\u58ec',
  266. '\u7678'
  267. ],
  268. /**
  269. * 天干地支之地支速查表
  270. * @Array Of Property
  271. * @trans["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]
  272. * @return Cn string
  273. */
  274. Zhi: [
  275. '\u5b50',
  276. '\u4e11',
  277. '\u5bc5',
  278. '\u536f',
  279. '\u8fb0',
  280. '\u5df3',
  281. '\u5348',
  282. '\u672a',
  283. '\u7533',
  284. '\u9149',
  285. '\u620c',
  286. '\u4ea5'
  287. ],
  288. /**
  289. * 天干地支之地支速查表<=>生肖
  290. * @Array Of Property
  291. * @trans["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]
  292. * @return Cn string
  293. */
  294. Animals: [
  295. '\u9f20',
  296. '\u725b',
  297. '\u864e',
  298. '\u5154',
  299. '\u9f99',
  300. '\u86c7',
  301. '\u9a6c',
  302. '\u7f8a',
  303. '\u7334',
  304. '\u9e21',
  305. '\u72d7',
  306. '\u732a'
  307. ],
  308. /**
  309. * 24节气速查表
  310. * @Array Of Property
  311. * @trans["小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"]
  312. * @return Cn string
  313. */
  314. solarTerm: [
  315. '\u5c0f\u5bd2',
  316. '\u5927\u5bd2',
  317. '\u7acb\u6625',
  318. '\u96e8\u6c34',
  319. '\u60ca\u86f0',
  320. '\u6625\u5206',
  321. '\u6e05\u660e',
  322. '\u8c37\u96e8',
  323. '\u7acb\u590f',
  324. '\u5c0f\u6ee1',
  325. '\u8292\u79cd',
  326. '\u590f\u81f3',
  327. '\u5c0f\u6691',
  328. '\u5927\u6691',
  329. '\u7acb\u79cb',
  330. '\u5904\u6691',
  331. '\u767d\u9732',
  332. '\u79cb\u5206',
  333. '\u5bd2\u9732',
  334. '\u971c\u964d',
  335. '\u7acb\u51ac',
  336. '\u5c0f\u96ea',
  337. '\u5927\u96ea',
  338. '\u51ac\u81f3'
  339. ],
  340. /**
  341. * 1900-2100各年的24节气日期速查表
  342. * @Array Of Property
  343. * @return 0x string For splice
  344. */
  345. sTermInfo: [
  346. '9778397bd097c36b0b6fc9274c91aa',
  347. '97b6b97bd19801ec9210c965cc920e',
  348. '97bcf97c3598082c95f8c965cc920f',
  349. '97bd0b06bdb0722c965ce1cfcc920f',
  350. 'b027097bd097c36b0b6fc9274c91aa',
  351. '97b6b97bd19801ec9210c965cc920e',
  352. '97bcf97c359801ec95f8c965cc920f',
  353. '97bd0b06bdb0722c965ce1cfcc920f',
  354. 'b027097bd097c36b0b6fc9274c91aa',
  355. '97b6b97bd19801ec9210c965cc920e',
  356. '97bcf97c359801ec95f8c965cc920f',
  357. '97bd0b06bdb0722c965ce1cfcc920f',
  358. 'b027097bd097c36b0b6fc9274c91aa',
  359. '9778397bd19801ec9210c965cc920e',
  360. '97b6b97bd19801ec95f8c965cc920f',
  361. '97bd09801d98082c95f8e1cfcc920f',
  362. '97bd097bd097c36b0b6fc9210c8dc2',
  363. '9778397bd197c36c9210c9274c91aa',
  364. '97b6b97bd19801ec95f8c965cc920e',
  365. '97bd09801d98082c95f8e1cfcc920f',
  366. '97bd097bd097c36b0b6fc9210c8dc2',
  367. '9778397bd097c36c9210c9274c91aa',
  368. '97b6b97bd19801ec95f8c965cc920e',
  369. '97bcf97c3598082c95f8e1cfcc920f',
  370. '97bd097bd097c36b0b6fc9210c8dc2',
  371. '9778397bd097c36c9210c9274c91aa',
  372. '97b6b97bd19801ec9210c965cc920e',
  373. '97bcf97c3598082c95f8c965cc920f',
  374. '97bd097bd097c35b0b6fc920fb0722',
  375. '9778397bd097c36b0b6fc9274c91aa',
  376. '97b6b97bd19801ec9210c965cc920e',
  377. '97bcf97c3598082c95f8c965cc920f',
  378. '97bd097bd097c35b0b6fc920fb0722',
  379. '9778397bd097c36b0b6fc9274c91aa',
  380. '97b6b97bd19801ec9210c965cc920e',
  381. '97bcf97c359801ec95f8c965cc920f',
  382. '97bd097bd097c35b0b6fc920fb0722',
  383. '9778397bd097c36b0b6fc9274c91aa',
  384. '97b6b97bd19801ec9210c965cc920e',
  385. '97bcf97c359801ec95f8c965cc920f',
  386. '97bd097bd097c35b0b6fc920fb0722',
  387. '9778397bd097c36b0b6fc9274c91aa',
  388. '97b6b97bd19801ec9210c965cc920e',
  389. '97bcf97c359801ec95f8c965cc920f',
  390. '97bd097bd07f595b0b6fc920fb0722',
  391. '9778397bd097c36b0b6fc9210c8dc2',
  392. '9778397bd19801ec9210c9274c920e',
  393. '97b6b97bd19801ec95f8c965cc920f',
  394. '97bd07f5307f595b0b0bc920fb0722',
  395. '7f0e397bd097c36b0b6fc9210c8dc2',
  396. '9778397bd097c36c9210c9274c920e',
  397. '97b6b97bd19801ec95f8c965cc920f',
  398. '97bd07f5307f595b0b0bc920fb0722',
  399. '7f0e397bd097c36b0b6fc9210c8dc2',
  400. '9778397bd097c36c9210c9274c91aa',
  401. '97b6b97bd19801ec9210c965cc920e',
  402. '97bd07f1487f595b0b0bc920fb0722',
  403. '7f0e397bd097c36b0b6fc9210c8dc2',
  404. '9778397bd097c36b0b6fc9274c91aa',
  405. '97b6b97bd19801ec9210c965cc920e',
  406. '97bcf7f1487f595b0b0bb0b6fb0722',
  407. '7f0e397bd097c35b0b6fc920fb0722',
  408. '9778397bd097c36b0b6fc9274c91aa',
  409. '97b6b97bd19801ec9210c965cc920e',
  410. '97bcf7f1487f595b0b0bb0b6fb0722',
  411. '7f0e397bd097c35b0b6fc920fb0722',
  412. '9778397bd097c36b0b6fc9274c91aa',
  413. '97b6b97bd19801ec9210c965cc920e',
  414. '97bcf7f1487f531b0b0bb0b6fb0722',
  415. '7f0e397bd097c35b0b6fc920fb0722',
  416. '9778397bd097c36b0b6fc9274c91aa',
  417. '97b6b97bd19801ec9210c965cc920e',
  418. '97bcf7f1487f531b0b0bb0b6fb0722',
  419. '7f0e397bd07f595b0b6fc920fb0722',
  420. '9778397bd097c36b0b6fc9274c91aa',
  421. '97b6b97bd19801ec9210c9274c920e',
  422. '97bcf7f0e47f531b0b0bb0b6fb0722',
  423. '7f0e397bd07f595b0b0bc920fb0722',
  424. '9778397bd097c36b0b6fc9210c91aa',
  425. '97b6b97bd197c36c9210c9274c920e',
  426. '97bcf7f0e47f531b0b0bb0b6fb0722',
  427. '7f0e397bd07f595b0b0bc920fb0722',
  428. '9778397bd097c36b0b6fc9210c8dc2',
  429. '9778397bd097c36c9210c9274c920e',
  430. '97b6b7f0e47f531b0723b0b6fb0722',
  431. '7f0e37f5307f595b0b0bc920fb0722',
  432. '7f0e397bd097c36b0b6fc9210c8dc2',
  433. '9778397bd097c36b0b70c9274c91aa',
  434. '97b6b7f0e47f531b0723b0b6fb0721',
  435. '7f0e37f1487f595b0b0bb0b6fb0722',
  436. '7f0e397bd097c35b0b6fc9210c8dc2',
  437. '9778397bd097c36b0b6fc9274c91aa',
  438. '97b6b7f0e47f531b0723b0b6fb0721',
  439. '7f0e27f1487f595b0b0bb0b6fb0722',
  440. '7f0e397bd097c35b0b6fc920fb0722',
  441. '9778397bd097c36b0b6fc9274c91aa',
  442. '97b6b7f0e47f531b0723b0b6fb0721',
  443. '7f0e27f1487f531b0b0bb0b6fb0722',
  444. '7f0e397bd097c35b0b6fc920fb0722',
  445. '9778397bd097c36b0b6fc9274c91aa',
  446. '97b6b7f0e47f531b0723b0b6fb0721',
  447. '7f0e27f1487f531b0b0bb0b6fb0722',
  448. '7f0e397bd097c35b0b6fc920fb0722',
  449. '9778397bd097c36b0b6fc9274c91aa',
  450. '97b6b7f0e47f531b0723b0b6fb0721',
  451. '7f0e27f1487f531b0b0bb0b6fb0722',
  452. '7f0e397bd07f595b0b0bc920fb0722',
  453. '9778397bd097c36b0b6fc9274c91aa',
  454. '97b6b7f0e47f531b0723b0787b0721',
  455. '7f0e27f0e47f531b0b0bb0b6fb0722',
  456. '7f0e397bd07f595b0b0bc920fb0722',
  457. '9778397bd097c36b0b6fc9210c91aa',
  458. '97b6b7f0e47f149b0723b0787b0721',
  459. '7f0e27f0e47f531b0723b0b6fb0722',
  460. '7f0e397bd07f595b0b0bc920fb0722',
  461. '9778397bd097c36b0b6fc9210c8dc2',
  462. '977837f0e37f149b0723b0787b0721',
  463. '7f07e7f0e47f531b0723b0b6fb0722',
  464. '7f0e37f5307f595b0b0bc920fb0722',
  465. '7f0e397bd097c35b0b6fc9210c8dc2',
  466. '977837f0e37f14998082b0787b0721',
  467. '7f07e7f0e47f531b0723b0b6fb0721',
  468. '7f0e37f1487f595b0b0bb0b6fb0722',
  469. '7f0e397bd097c35b0b6fc9210c8dc2',
  470. '977837f0e37f14998082b0787b06bd',
  471. '7f07e7f0e47f531b0723b0b6fb0721',
  472. '7f0e27f1487f531b0b0bb0b6fb0722',
  473. '7f0e397bd097c35b0b6fc920fb0722',
  474. '977837f0e37f14998082b0787b06bd',
  475. '7f07e7f0e47f531b0723b0b6fb0721',
  476. '7f0e27f1487f531b0b0bb0b6fb0722',
  477. '7f0e397bd097c35b0b6fc920fb0722',
  478. '977837f0e37f14998082b0787b06bd',
  479. '7f07e7f0e47f531b0723b0b6fb0721',
  480. '7f0e27f1487f531b0b0bb0b6fb0722',
  481. '7f0e397bd07f595b0b0bc920fb0722',
  482. '977837f0e37f14998082b0787b06bd',
  483. '7f07e7f0e47f531b0723b0b6fb0721',
  484. '7f0e27f1487f531b0b0bb0b6fb0722',
  485. '7f0e397bd07f595b0b0bc920fb0722',
  486. '977837f0e37f14998082b0787b06bd',
  487. '7f07e7f0e47f149b0723b0787b0721',
  488. '7f0e27f0e47f531b0b0bb0b6fb0722',
  489. '7f0e397bd07f595b0b0bc920fb0722',
  490. '977837f0e37f14998082b0723b06bd',
  491. '7f07e7f0e37f149b0723b0787b0721',
  492. '7f0e27f0e47f531b0723b0b6fb0722',
  493. '7f0e397bd07f595b0b0bc920fb0722',
  494. '977837f0e37f14898082b0723b02d5',
  495. '7ec967f0e37f14998082b0787b0721',
  496. '7f07e7f0e47f531b0723b0b6fb0722',
  497. '7f0e37f1487f595b0b0bb0b6fb0722',
  498. '7f0e37f0e37f14898082b0723b02d5',
  499. '7ec967f0e37f14998082b0787b0721',
  500. '7f07e7f0e47f531b0723b0b6fb0722',
  501. '7f0e37f1487f531b0b0bb0b6fb0722',
  502. '7f0e37f0e37f14898082b0723b02d5',
  503. '7ec967f0e37f14998082b0787b06bd',
  504. '7f07e7f0e47f531b0723b0b6fb0721',
  505. '7f0e37f1487f531b0b0bb0b6fb0722',
  506. '7f0e37f0e37f14898082b072297c35',
  507. '7ec967f0e37f14998082b0787b06bd',
  508. '7f07e7f0e47f531b0723b0b6fb0721',
  509. '7f0e27f1487f531b0b0bb0b6fb0722',
  510. '7f0e37f0e37f14898082b072297c35',
  511. '7ec967f0e37f14998082b0787b06bd',
  512. '7f07e7f0e47f531b0723b0b6fb0721',
  513. '7f0e27f1487f531b0b0bb0b6fb0722',
  514. '7f0e37f0e366aa89801eb072297c35',
  515. '7ec967f0e37f14998082b0787b06bd',
  516. '7f07e7f0e47f149b0723b0787b0721',
  517. '7f0e27f1487f531b0b0bb0b6fb0722',
  518. '7f0e37f0e366aa89801eb072297c35',
  519. '7ec967f0e37f14998082b0723b06bd',
  520. '7f07e7f0e47f149b0723b0787b0721',
  521. '7f0e27f0e47f531b0723b0b6fb0722',
  522. '7f0e37f0e366aa89801eb072297c35',
  523. '7ec967f0e37f14998082b0723b06bd',
  524. '7f07e7f0e37f14998083b0787b0721',
  525. '7f0e27f0e47f531b0723b0b6fb0722',
  526. '7f0e37f0e366aa89801eb072297c35',
  527. '7ec967f0e37f14898082b0723b02d5',
  528. '7f07e7f0e37f14998082b0787b0721',
  529. '7f07e7f0e47f531b0723b0b6fb0722',
  530. '7f0e36665b66aa89801e9808297c35',
  531. '665f67f0e37f14898082b0723b02d5',
  532. '7ec967f0e37f14998082b0787b0721',
  533. '7f07e7f0e47f531b0723b0b6fb0722',
  534. '7f0e36665b66a449801e9808297c35',
  535. '665f67f0e37f14898082b0723b02d5',
  536. '7ec967f0e37f14998082b0787b06bd',
  537. '7f07e7f0e47f531b0723b0b6fb0721',
  538. '7f0e36665b66a449801e9808297c35',
  539. '665f67f0e37f14898082b072297c35',
  540. '7ec967f0e37f14998082b0787b06bd',
  541. '7f07e7f0e47f531b0723b0b6fb0721',
  542. '7f0e26665b66a449801e9808297c35',
  543. '665f67f0e37f1489801eb072297c35',
  544. '7ec967f0e37f14998082b0787b06bd',
  545. '7f07e7f0e47f531b0723b0b6fb0721',
  546. '7f0e27f1487f531b0b0bb0b6fb0722'
  547. ],
  548. /**
  549. * 数字转中文速查表
  550. * @Array Of Property
  551. * @trans ['日','一','二','三','四','五','六','七','八','九','十']
  552. * @return Cn string
  553. */
  554. nStr1: [
  555. '\u65e5',
  556. '\u4e00',
  557. '\u4e8c',
  558. '\u4e09',
  559. '\u56db',
  560. '\u4e94',
  561. '\u516d',
  562. '\u4e03',
  563. '\u516b',
  564. '\u4e5d',
  565. '\u5341'
  566. ],
  567. /**
  568. * 日期转农历称呼速查表
  569. * @Array Of Property
  570. * @trans ['初','十','廿','卅']
  571. * @return Cn string
  572. */
  573. nStr2: ['\u521d', '\u5341', '\u5eff', '\u5345'],
  574. /**
  575. * 月份转农历称呼速查表
  576. * @Array Of Property
  577. * @trans ['正','一','二','三','四','五','六','七','八','九','十','冬','腊']
  578. * @return Cn string
  579. */
  580. nStr3: [
  581. '\u6b63',
  582. '\u4e8c',
  583. '\u4e09',
  584. '\u56db',
  585. '\u4e94',
  586. '\u516d',
  587. '\u4e03',
  588. '\u516b',
  589. '\u4e5d',
  590. '\u5341',
  591. '\u51ac',
  592. '\u814a'
  593. ],
  594. /**
  595. * 返回农历y年一整年的总天数
  596. * @param lunar Year
  597. * @return Number
  598. * @eg:var count = calendar.lYearDays(1987) ;//count=387
  599. */
  600. lYearDays: function(y) {
  601. let i
  602. let sum = 348
  603. for (i = 0x8000; i > 0x8; i >>= 1) {
  604. sum += calendar.lunarInfo[y - 1900] & i ? 1 : 0
  605. }
  606. return sum + calendar.leapDays(y)
  607. },
  608. /**
  609. * 返回农历y年闰月是哪个月;若y年没有闰月 则返回0
  610. * @param lunar Year
  611. * @return Number (0-12)
  612. * @eg:var leapMonth = calendar.leapMonth(1987) ;//leapMonth=6
  613. */
  614. leapMonth: function(y) {
  615. // 闰字编码 \u95f0
  616. return calendar.lunarInfo[y - 1900] & 0xf
  617. },
  618. /**
  619. * 返回农历y年闰月的天数 若该年没有闰月则返回0
  620. * @param lunar Year
  621. * @return Number (0、29、30)
  622. * @eg:var leapMonthDay = calendar.leapDays(1987) ;//leapMonthDay=29
  623. */
  624. leapDays: function(y) {
  625. if (calendar.leapMonth(y)) {
  626. return calendar.lunarInfo[y - 1900] & 0x10000 ? 30 : 29
  627. }
  628. return 0
  629. },
  630. /**
  631. * 返回农历y年m月(非闰月)的总天数,计算m为闰月时的天数请使用leapDays方法
  632. * @param lunar Year
  633. * @return Number (-1、29、30)
  634. * @eg:var MonthDay = calendar.monthDays(1987,9) ;//MonthDay=29
  635. */
  636. monthDays: function(y, m) {
  637. if (m > 12 || m < 1) return -1 // 月份参数从1至12,参数错误返回-1
  638. return calendar.lunarInfo[y - 1900] & (0x10000 >> m) ? 30 : 29
  639. },
  640. /**
  641. * 返回公历(!)y年m月的天数
  642. * @param solar Year
  643. * @return Number (-1、28、29、30、31)
  644. * @eg:var solarMonthDay = calendar.leapDays(1987) ;//solarMonthDay=30
  645. */
  646. solarDays: function(y, m) {
  647. if (m > 12 || m < 1) return -1 // 若参数错误 返回-1
  648. const ms = m - 1
  649. if (+ms === 1) {
  650. // 2月份的闰平规律测算后确认返回28或29
  651. return (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0 ? 29 : 28
  652. } else {
  653. return calendar.solarMonth[ms]
  654. }
  655. },
  656. /**
  657. * 农历年份转换为干支纪年
  658. * @param lYear 农历年的年份数
  659. * @return Cn string
  660. */
  661. toGanZhiYear: function(lYear) {
  662. let ganKey = (lYear - 3) % 10
  663. let zhiKey = (lYear - 3) % 12
  664. if (+ganKey === 0) ganKey = 10 // 如果余数为0则为最后一个天干
  665. if (+zhiKey === 0) zhiKey = 12 // 如果余数为0则为最后一个地支
  666. return calendar.Gan[ganKey - 1] + calendar.Zhi[zhiKey - 1]
  667. },
  668. /**
  669. * 公历月、日判断所属星座
  670. * @param cMonth [description]
  671. * @param cDay [description]
  672. * @return Cn string
  673. */
  674. toAstro: function(cMonth, cDay) {
  675. const s =
  676. '\u9b54\u7faf\u6c34\u74f6\u53cc\u9c7c\u767d\u7f8a\u91d1\u725b\u53cc\u5b50\u5de8\u87f9\u72ee\u5b50\u5904\u5973\u5929\u79e4\u5929\u874e\u5c04\u624b\u9b54\u7faf'
  677. const arr = [20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22]
  678. return s.substr(cMonth * 2 - (cDay < arr[cMonth - 1] ? 2 : 0), 2) + '\u5ea7' // 座
  679. },
  680. /**
  681. * 传入offset偏移量返回干支
  682. * @param offset 相对甲子的偏移量
  683. * @return Cn string
  684. */
  685. toGanZhi: function(offset) {
  686. return calendar.Gan[offset % 10] + calendar.Zhi[offset % 12]
  687. },
  688. /**
  689. * 传入公历(!)y年获得该年第n个节气的公历日期
  690. * @param y公历年(1900-2100);n二十四节气中的第几个节气(1~24);从n=1(小寒)算起
  691. * @return day Number
  692. * @eg:var _24 = calendar.getTerm(1987,3) ;//_24=4;意即1987年2月4日立春
  693. */
  694. getTerm: function(y, n) {
  695. if (y < 1900 || y > 2100) return -1
  696. if (n < 1 || n > 24) return -1
  697. const _table = calendar.sTermInfo[y - 1900]
  698. const _info = [
  699. parseInt('0x' + _table.substr(0, 5)).toString(),
  700. parseInt('0x' + _table.substr(5, 5)).toString(),
  701. parseInt('0x' + _table.substr(10, 5)).toString(),
  702. parseInt('0x' + _table.substr(15, 5)).toString(),
  703. parseInt('0x' + _table.substr(20, 5)).toString(),
  704. parseInt('0x' + _table.substr(25, 5)).toString()
  705. ]
  706. const _calday = [
  707. _info[0].substr(0, 1),
  708. _info[0].substr(1, 2),
  709. _info[0].substr(3, 1),
  710. _info[0].substr(4, 2),
  711. _info[1].substr(0, 1),
  712. _info[1].substr(1, 2),
  713. _info[1].substr(3, 1),
  714. _info[1].substr(4, 2),
  715. _info[2].substr(0, 1),
  716. _info[2].substr(1, 2),
  717. _info[2].substr(3, 1),
  718. _info[2].substr(4, 2),
  719. _info[3].substr(0, 1),
  720. _info[3].substr(1, 2),
  721. _info[3].substr(3, 1),
  722. _info[3].substr(4, 2),
  723. _info[4].substr(0, 1),
  724. _info[4].substr(1, 2),
  725. _info[4].substr(3, 1),
  726. _info[4].substr(4, 2),
  727. _info[5].substr(0, 1),
  728. _info[5].substr(1, 2),
  729. _info[5].substr(3, 1),
  730. _info[5].substr(4, 2)
  731. ]
  732. return parseInt(_calday[n - 1])
  733. },
  734. /**
  735. * 传入农历数字月份返回汉语通俗表示法
  736. * @param lunar month
  737. * @return Cn string
  738. * @eg:var cnMonth = calendar.toChinaMonth(12) ;//cnMonth='腊月'
  739. */
  740. toChinaMonth: function(m) {
  741. // 月 => \u6708
  742. if (m > 12 || m < 1) return -1 // 若参数错误 返回-1
  743. let s = calendar.nStr3[m - 1]
  744. s += '\u6708' // 加上月字
  745. return s
  746. },
  747. /**
  748. * 传入农历日期数字返回汉字表示法
  749. * @param lunar day
  750. * @return Cn string
  751. * @eg:var cnDay = calendar.toChinaDay(21) ;//cnMonth='廿一'
  752. */
  753. toChinaDay: function(d) {
  754. // 日 => \u65e5
  755. let s
  756. switch (d) {
  757. case 10:
  758. s = '\u521d\u5341'
  759. break
  760. case 20:
  761. s = '\u4e8c\u5341'
  762. break
  763. case 30:
  764. s = '\u4e09\u5341'
  765. break
  766. default:
  767. s = calendar.nStr2[Math.floor(d / 10)]
  768. s += calendar.nStr1[d % 10]
  769. }
  770. return s
  771. },
  772. /**
  773. * 年份转生肖[!仅能大致转换] => 精确划分生肖分界线是“立春”
  774. * @param y year
  775. * @return Cn string
  776. * @eg:var animal = calendar.getAnimal(1987) ;//animal='兔'
  777. */
  778. getAnimal: function(y) {
  779. return calendar.Animals[(y - 4) % 12]
  780. },
  781. /**
  782. * 传入阳历年月日获得详细的公历、农历object信息 <=>JSON
  783. * @param y solar year
  784. * @param m solar month
  785. * @param d solar day
  786. * @return JSON object
  787. * @eg:console.log(calendar.solar2lunar(1987,11,01));
  788. */
  789. solar2lunar: function(y, m, d) {
  790. // 参数区间1900.1.31~2100.12.31
  791. // 年份限定、上限
  792. if (y < 1900 || y > 2100) {
  793. return -1 // undefined转换为数字变为NaN
  794. }
  795. // 公历传参最下限
  796. if (+y === 1900 && +m === 1 && +d < 31) {
  797. return -1
  798. }
  799. // 未传参 获得当天
  800. let objDate
  801. if (!y) {
  802. objDate = new Date()
  803. } else {
  804. objDate = new Date(y, parseInt(m) - 1, d)
  805. }
  806. let i
  807. let leap = 0
  808. let temp = 0
  809. // 修正ymd参数
  810. y = objDate.getFullYear()
  811. m = objDate.getMonth() + 1
  812. d = objDate.getDate()
  813. let offset =
  814. (Date.UTC(objDate.getFullYear(), objDate.getMonth(), objDate.getDate()) -
  815. Date.UTC(1900, 0, 31)) /
  816. 86400000
  817. for (i = 1900; i < 2101 && offset > 0; i++) {
  818. temp = calendar.lYearDays(i)
  819. offset -= temp
  820. }
  821. if (offset < 0) {
  822. offset += temp
  823. i--
  824. }
  825. // 是否今天
  826. const isTodayObj = new Date()
  827. let isToday = false
  828. if (
  829. isTodayObj.getFullYear() === +y &&
  830. isTodayObj.getMonth() + 1 === +m &&
  831. isTodayObj.getDate() === +d
  832. ) {
  833. isToday = true
  834. }
  835. // 星期几
  836. let nWeek = objDate.getDay()
  837. const cWeek = calendar.nStr1[nWeek]
  838. // 数字表示周几顺应天朝周一开始的惯例
  839. if (+nWeek === 0) {
  840. nWeek = 7
  841. }
  842. // 农历年
  843. const year = i
  844. leap = calendar.leapMonth(i) // 闰哪个月
  845. let isLeap = false
  846. // 效验闰月
  847. for (i = 1; i < 13 && offset > 0; i++) {
  848. // 闰月
  849. if (leap > 0 && i === leap + 1 && isLeap === false) {
  850. --i
  851. isLeap = true
  852. temp = calendar.leapDays(year) // 计算农历闰月天数
  853. } else {
  854. temp = calendar.monthDays(year, i) // 计算农历普通月天数
  855. }
  856. // 解除闰月
  857. if (isLeap === true && i === leap + 1) isLeap = false
  858. offset -= temp
  859. }
  860. // 闰月导致数组下标重叠取反
  861. if (offset === 0 && leap > 0 && i === leap + 1) {
  862. if (isLeap) {
  863. isLeap = false
  864. } else {
  865. isLeap = true
  866. --i
  867. }
  868. }
  869. if (offset < 0) {
  870. offset += temp
  871. --i
  872. }
  873. // 农历月
  874. const month = i
  875. // 农历日
  876. const day = offset + 1
  877. // 天干地支处理
  878. const sm = m - 1
  879. const gzY = calendar.toGanZhiYear(year)
  880. // 当月的两个节气
  881. // bugfix-2017-7-24 11:03:38 use lunar Year Param `y` Not `year`
  882. const firstNode = calendar.getTerm(y, m * 2 - 1) // 返回当月「节」为几日开始
  883. const secondNode = calendar.getTerm(y, m * 2) // 返回当月「节」为几日开始
  884. // 依据12节气修正干支月
  885. let gzM = calendar.toGanZhi((y - 1900) * 12 + m + 11)
  886. if (d >= firstNode) {
  887. gzM = calendar.toGanZhi((y - 1900) * 12 + m + 12)
  888. }
  889. // 传入的日期的节气与否
  890. let isTerm = false
  891. let Term = null
  892. if (+firstNode === d) {
  893. isTerm = true
  894. Term = calendar.solarTerm[m * 2 - 2]
  895. }
  896. if (+secondNode === d) {
  897. isTerm = true
  898. Term = calendar.solarTerm[m * 2 - 1]
  899. }
  900. // 日柱 当月一日与 1900/1/1 相差天数
  901. const dayCyclical = Date.UTC(y, sm, 1, 0, 0, 0, 0) / 86400000 + 25567 + 10
  902. const gzD = calendar.toGanZhi(dayCyclical + d - 1)
  903. // 该日期所属的星座
  904. const astro = calendar.toAstro(m, d)
  905. return {
  906. lYear: year,
  907. lMonth: month,
  908. lDay: day,
  909. Animal: calendar.getAnimal(year),
  910. IMonthCn: (isLeap ? '\u95f0' : '') + calendar.toChinaMonth(month),
  911. IDayCn: calendar.toChinaDay(day),
  912. cYear: y,
  913. cMonth: m,
  914. cDay: d,
  915. gzYear: gzY,
  916. gzMonth: gzM,
  917. gzDay: gzD,
  918. isToday: isToday,
  919. isLeap: isLeap,
  920. nWeek: nWeek,
  921. ncWeek: '\u661f\u671f' + cWeek,
  922. isTerm: isTerm,
  923. Term: Term,
  924. astro: astro
  925. }
  926. },
  927. /**
  928. * 传入农历年月日以及传入的月份是否闰月获得详细的公历、农历object信息 <=>JSON
  929. * @param y lunar year
  930. * @param m lunar month
  931. * @param d lunar day
  932. * @param isLeapMonth lunar month is leap or not.[如果是农历闰月第四个参数赋值true即可]
  933. * @return JSON object
  934. * @eg:console.log(calendar.lunar2solar(1987,9,10));
  935. */
  936. lunar2solar: function(y, m, d, isLeapMonth) {
  937. // 参数区间1900.1.31~2100.12.1
  938. isLeapMonth = !!isLeapMonth
  939. // let leapOffset = 0;
  940. const leapMonth = calendar.leapMonth(y)
  941. // let leapDay = calendar.leapDays(y);
  942. if (isLeapMonth && leapMonth !== m) return -1 // 传参要求计算该闰月公历 但该年得出的闰月与传参的月份并不同
  943. if (
  944. (+y === 2100 && +m === 12 && +d > 1) ||
  945. (+y === 1900 && +m === 1 && +d < 31)
  946. )
  947. return -1 // 超出了最大极限值
  948. const day = calendar.monthDays(y, m)
  949. let _day = day
  950. // bugFix 2016-9-25
  951. // if month is leap, _day use leapDays method
  952. if (isLeapMonth) {
  953. _day = calendar.leapDays(y, m)
  954. }
  955. if (y < 1900 || y > 2100 || d > _day) return -1 // 参数合法性效验
  956. // 计算农历的时间差
  957. let offset = 0
  958. for (let i = 1900; i < y; i++) {
  959. offset += calendar.lYearDays(i)
  960. }
  961. let leap = 0
  962. let isAdd = false
  963. for (let i = 1; i < m; i++) {
  964. leap = calendar.leapMonth(y)
  965. if (!isAdd) {
  966. // 处理闰月
  967. if (leap <= i && leap > 0) {
  968. offset += calendar.leapDays(y)
  969. isAdd = true
  970. }
  971. }
  972. offset += calendar.monthDays(y, i)
  973. }
  974. // 转换闰月农历 需补充该年闰月的前一个月的时差
  975. if (isLeapMonth) offset += day
  976. // 1900年农历正月一日的公历时间为1900年1月30日0时0分0秒(该时间也是本农历的最开始起始点)
  977. const stmap = Date.UTC(1900, 1, 30, 0, 0, 0)
  978. const calObj = new Date((offset + d - 31) * 86400000 + stmap)
  979. const cY = calObj.getUTCFullYear()
  980. const cM = calObj.getUTCMonth() + 1
  981. const cD = calObj.getUTCDate()
  982. return calendar.solar2lunar(cY, cM, cD)
  983. }
  984. }
  985. const {
  986. Gan,
  987. Zhi,
  988. nStr1,
  989. nStr2,
  990. nStr3,
  991. Animals,
  992. solarTerm,
  993. lunarInfo,
  994. sTermInfo,
  995. solarMonth,
  996. ...rest
  997. } = calendar
  998. export default rest