PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/static/lunar.html

https://github.com/lostab/log
HTML | 627 lines | 107 code | 15 blank | 505 comment | 0 complexity | f17da5b566df7877ac1aa2f9a680ccd9 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <!doctype html>
  2. <meta charset="utf-8" />
  3. <meta name="viewport" content="maximum-scale=1.0,width=device-width,initial-scale=1.0" />
  4. <title>农历</title>
  5. <table cellpadding="0" cellspacing="0" id="1">
  6. <tr>
  7. <td>
  8. <style>
  9. body,td,.p1,.p2,.i {
  10. text-align: center;
  11. }
  12. body {
  13. margin: 0;
  14. background-color: #fff;
  15. color: #000;
  16. }
  17. table {
  18. border: 0;
  19. width: 100%;
  20. }
  21. #cal {
  22. width:100%;
  23. border: 0px solid #c3d9ff;
  24. font-size: 12px;
  25. }
  26. #cal #top {
  27. height: 29px;
  28. line-height: 29px;
  29. background: #e7eef8;
  30. color: #003784;
  31. text-align: center;
  32. }
  33. #cal #top select {
  34. font-size: 12px
  35. }
  36. #cal #top input {
  37. padding: 0
  38. }
  39. #cal ul#wk {
  40. margin: 0;
  41. padding: 0;
  42. height: 25px;
  43. }
  44. #cal ul#wk li {
  45. float: left;
  46. width: 14%;
  47. text-align: center;
  48. line-height: 25px;
  49. list-style: none;
  50. }
  51. #cal ul#wk li:first-child {
  52. margin-left: 1%;
  53. }
  54. #cal ul#wk li b {
  55. font-weight: normal;
  56. color: #c60b02
  57. }
  58. #cal #cm {
  59. clear: left;
  60. border-top: 1px solid #ddd;
  61. border-bottom: 1px dotted #ddd;
  62. position: relative
  63. }
  64. #cal #cm .cell {
  65. position: absolute;
  66. width: 14%;
  67. height: 36px;
  68. text-align: center;
  69. margin: 0
  70. }
  71. #cal #cm .cell .so {
  72. font: bold 16px arial;
  73. }
  74. #cal #fd {
  75. display: none;
  76. position: absolute;
  77. border: 1px solid #dddddf;
  78. background: #feffcd;
  79. line-height: 21px;
  80. width: 60%;
  81. }
  82. #cal #fd b {
  83. font-weight: normal;
  84. color: #c60a00
  85. }
  86. </style>
  87. <!--[if IE]>
  88. <style>
  89. #cal #top{padding-top:4px}
  90. #cal #top input{width:65px}
  91. #cal #fd{width:170px}
  92. </style>
  93. <![endif]-->
  94. <div id="cal">
  95. <div id="top"><select>
  96. </select><select>
  97. </select> <span></span> <span></span> <input type="button"
  98. value="今天" title="今天" style="padding: 0px"></div>
  99. <ul id="wk">
  100. <li><b></b></li>
  101. <li></li>
  102. <li></li>
  103. <li></li>
  104. <li></li>
  105. <li></li>
  106. <li><b></b></li>
  107. </ul>
  108. <div id="cm"></div>
  109. </div>
  110. </td>
  111. </tr>
  112. </table>
  113. <script type="text/javascript">
  114. <!--
  115. (function() {
  116. var S = navigator.userAgent.indexOf("MSIE") != -1 && !window.opera;
  117. function M(C) {
  118. return document.getElementById(C)
  119. }
  120. function R(C) {
  121. return document.createElement(C)
  122. }
  123. var P = [ 19416, 19168, 42352, 21717, 53856, 55632, 91476, 22176,
  124. 39632, 21970, 19168, 42422, 42192, 53840, 119381, 46400, 54944,
  125. 44450, 38320, 84343, 18800, 42160, 46261, 27216, 27968, 109396,
  126. 11104, 38256, 21234, 18800, 25958, 54432, 59984, 28309, 23248,
  127. 11104, 100067, 37600, 116951, 51536, 54432, 120998, 46416,
  128. 22176, 107956, 9680, 37584, 53938, 43344, 46423, 27808, 46416,
  129. 86869, 19872, 42448, 83315, 21200, 43432, 59728, 27296, 44710,
  130. 43856, 19296, 43748, 42352, 21088, 62051, 55632, 23383, 22176,
  131. 38608, 19925, 19152, 42192, 54484, 53840, 54616, 46400, 46496,
  132. 103846, 38320, 18864, 43380, 42160, 45690, 27216, 27968, 44870,
  133. 43872, 38256, 19189, 18800, 25776, 29859, 59984, 27480, 21952,
  134. 43872, 38613, 37600, 51552, 55636, 54432, 55888, 30034, 22176,
  135. 43959, 9680, 37584, 51893, 43344, 46240, 47780, 44368, 21977,
  136. 19360, 42416, 86390, 21168, 43312, 31060, 27296, 44368, 23378,
  137. 19296, 42726, 42208, 53856, 60005, 54576, 23200, 30371, 38608,
  138. 19415, 19152, 42192, 118966, 53840, 54560, 56645, 46496, 22224,
  139. 21938, 18864, 42359, 42160, 43600, 111189, 27936, 44448 ];
  140. var K = "甲乙丙丁戊己庚辛壬癸";
  141. var J = "子丑寅卯辰巳午未申酉戌亥";
  142. var O = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
  143. var L = [ "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满",
  144. "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降",
  145. "立冬", "小雪", "大雪", "冬至" ];
  146. var D = [ 0, 21208, 43467, 63836, 85337, 107014, 128867, 150921,
  147. 173149, 195551, 218072, 240693, 263343, 285989, 308563, 331033,
  148. 353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758 ];
  149. var B = "日一二三四五六七八九十";
  150. var H = [ "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊" ];
  151. var E = "初十廿卅";
  152. var V = {
  153. "0101" : "*1元旦节",
  154. "0214" : "情人节",
  155. "0305" : "学雷锋纪念日",
  156. "0308" : "妇女节",
  157. "0312" : "植树节",
  158. "0315" : "消费者权益日",
  159. "0401" : "愚人节",
  160. "0501" : "*1劳动节",
  161. "0504" : "青年节",
  162. "0601" : "国际儿童节",
  163. "0701" : "中国共产党诞辰",
  164. "0801" : "建军节",
  165. "0910" : "中国教师节",
  166. "1001" : "*3国庆节",
  167. "1224" : "平安夜",
  168. "1225" : "圣诞节"
  169. };
  170. var T = {
  171. "0101" : "*2春节",
  172. "0115" : "元宵节",
  173. "0505" : "*1端午节",
  174. "0815" : "*1中秋节",
  175. "0909" : "重阳节",
  176. "1208" : "腊八节",
  177. "0100" : "除夕"
  178. };
  179. function U(Y) {
  180. function c(j, i) {
  181. var h = new Date((31556925974.7 * (j - 1900) + D[i] * 60000)
  182. + Date.UTC(1900, 0, 6, 2, 5));
  183. return (h.getUTCDate())
  184. }
  185. function d(k) {
  186. var h, j = 348;
  187. for (h = 32768; h > 8; h >>= 1) {
  188. j += (P[k - 1900] & h) ? 1 : 0
  189. }
  190. return (j + b(k))
  191. }
  192. function a(h) {
  193. return (K.charAt(h % 10) + J.charAt(h % 12))
  194. }
  195. function b(h) {
  196. if (g(h)) {
  197. return ((P[h - 1900] & 65536) ? 30 : 29)
  198. } else {
  199. return (0)
  200. }
  201. }
  202. function g(h) {
  203. return (P[h - 1900] & 15)
  204. }
  205. function e(i, h) {
  206. return ((P[i - 1900] & (65536 >> h)) ? 30 : 29)
  207. }
  208. function C(m) {
  209. var k, j = 0, h = 0;
  210. var l = new Date(1900, 0, 31);
  211. var n = (m - l) / 86400000;
  212. this.dayCyl = n + 40;
  213. this.monCyl = 14;
  214. for (k = 1900; k<2050&&n>0; k++) {
  215. h = d(k);
  216. n -= h;
  217. this.monCyl += 12
  218. }
  219. if (n < 0) {
  220. n += h;
  221. k--;
  222. this.monCyl -= 12
  223. }
  224. this.year = k;
  225. this.yearCyl = k - 1864;
  226. j = g(k);
  227. this.isLeap = false;
  228. for (k = 1; k<13&&n>0; k++) {
  229. if (j > 0 && k == (j + 1) && this.isLeap == false) {
  230. --k;
  231. this.isLeap = true;
  232. h = b(this.year)
  233. } else {
  234. h = e(this.year, k)
  235. }
  236. if (this.isLeap == true && k == (j + 1)) {
  237. this.isLeap = false
  238. }
  239. n -= h;
  240. if (this.isLeap == false) {
  241. this.monCyl++
  242. }
  243. }
  244. if (n == 0 && j > 0 && k == j + 1) {
  245. if (this.isLeap) {
  246. this.isLeap = false
  247. } else {
  248. this.isLeap = true;
  249. --k;
  250. --this.monCyl
  251. }
  252. }
  253. if (n < 0) {
  254. n += h;
  255. --k;
  256. --this.monCyl
  257. }
  258. this.month = k;
  259. this.day = n + 1
  260. }
  261. function G(h) {
  262. return h < 10 ? "0" + h : h
  263. }
  264. function f(i, j) {
  265. var h = i;
  266. return j.replace(/dd?d?d?|MM?M?M?|yy?y?y?/g, function(k) {
  267. switch (k) {
  268. case "yyyy":
  269. var l = "000" + h.getFullYear();
  270. return l.substring(l.length - 4);
  271. case "dd":
  272. return G(h.getDate());
  273. case "d":
  274. return h.getDate().toString();
  275. case "MM":
  276. return G((h.getMonth() + 1));
  277. case "M":
  278. return h.getMonth() + 1
  279. }
  280. })
  281. }
  282. function Z(i, h) {
  283. var j;
  284. switch (i, h) {
  285. case 10:
  286. j = "初十";
  287. break;
  288. case 20:
  289. j = "二十";
  290. break;
  291. case 30:
  292. j = "三十";
  293. break;
  294. default:
  295. j = E.charAt(Math.floor(h / 10));
  296. j += B.charAt(h % 10)
  297. }
  298. return (j)
  299. }
  300. this.date = Y;
  301. this.isToday = false;
  302. this.isRestDay = false;
  303. this.solarYear = f(Y, "yyyy");
  304. this.solarMonth = f(Y, "M");
  305. this.solarDate = f(Y, "d");
  306. this.solarWeekDay = Y.getDay();
  307. this.solarWeekDayInChinese = "星期" + B.charAt(this.solarWeekDay);
  308. var X = new C(Y);
  309. this.lunarYear = X.year;
  310. this.shengxiao = O.charAt((this.lunarYear - 4) % 12);
  311. this.lunarMonth = X.month;
  312. this.lunarIsLeapMonth = X.isLeap;
  313. this.lunarMonthInChinese = this.lunarIsLeapMonth ? "闰"
  314. + H[X.month - 1] : H[X.month - 1];
  315. this.lunarDate = X.day;
  316. this.showInLunar = this.lunarDateInChinese = Z(this.lunarMonth,
  317. this.lunarDate);
  318. if (this.lunarDate == 1) {
  319. this.showInLunar = this.lunarMonthInChinese + "月"
  320. }
  321. this.ganzhiYear = a(X.yearCyl);
  322. this.ganzhiMonth = a(X.monCyl);
  323. this.ganzhiDate = a(X.dayCyl++);
  324. this.jieqi = "";
  325. this.restDays = 0;
  326. if (c(this.solarYear, (this.solarMonth - 1) * 2) == f(Y, "d")) {
  327. this.showInLunar = this.jieqi = L[(this.solarMonth - 1) * 2]
  328. }
  329. if (c(this.solarYear, (this.solarMonth - 1) * 2 + 1) == f(Y, "d")) {
  330. this.showInLunar = this.jieqi = L[(this.solarMonth - 1) * 2 + 1]
  331. }
  332. if (this.showInLunar == "清明") {
  333. this.showInLunar = "清明节";
  334. this.restDays = 1
  335. }
  336. this.solarFestival = V[f(Y, "MM") + f(Y, "dd")];
  337. if (typeof this.solarFestival == "undefined") {
  338. this.solarFestival = ""
  339. } else {
  340. if (/\*(\d)/.test(this.solarFestival)) {
  341. this.restDays = parseInt(RegExp.$1);
  342. this.solarFestival = this.solarFestival.replace(/\*\d/, "")
  343. }
  344. }
  345. this.showInLunar = (this.solarFestival == "") ? this.showInLunar
  346. : this.solarFestival;
  347. this.lunarFestival = T[this.lunarIsLeapMonth ? "00"
  348. : G(this.lunarMonth) + G(this.lunarDate)];
  349. if (typeof this.lunarFestival == "undefined") {
  350. this.lunarFestival = ""
  351. } else {
  352. if (/\*(\d)/.test(this.lunarFestival)) {
  353. this.restDays = (this.restDays > parseInt(RegExp.$1)) ? this.restDays
  354. : parseInt(RegExp.$1);
  355. this.lunarFestival = this.lunarFestival.replace(/\*\d/, "")
  356. }
  357. }
  358. if (this.lunarMonth == 12
  359. && this.lunarDate == e(this.lunarYear, 12)) {
  360. this.lunarFestival = T["0100"];
  361. this.restDays = 1
  362. }
  363. this.showInLunar = (this.lunarFestival == "") ? this.showInLunar
  364. : this.lunarFestival;
  365. this.showInLunar = (this.showInLunar.length > 4) ? this.showInLunar
  366. .substr(0, 2)
  367. + "..." : this.showInLunar
  368. }
  369. var Q = (function() {
  370. var X = {};
  371. X.lines = 0;
  372. X.dateArray = new Array(42);
  373. function Y(a) {
  374. return (((a % 4 === 0) && (a % 100 !== 0)) || (a % 400 === 0))
  375. }
  376. function G(a, b) {
  377. return [ 31, (Y(a) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31,
  378. 30, 31 ][b]
  379. }
  380. function C(a, b) {
  381. a.setDate(a.getDate() + b);
  382. return a
  383. }
  384. function Z(a) {
  385. var f = 0;
  386. var c = new U(new Date(a.solarYear, a.solarMonth - 1, 1));
  387. //var d = (c.solarWeekDay - 1 == -1) ? 6 : c.solarWeekDay - 1;
  388. var d = c.solarWeekDay;
  389. X.lines = Math.ceil((d + G(a.solarYear, a.solarMonth - 1)) / 7);
  390. for ( var e = 0; e < X.dateArray.length; e++) {
  391. if (c.restDays != 0) {
  392. f = c.restDays
  393. }
  394. if (f > 0) {
  395. c.isRest = true
  396. }
  397. if (d-- > 0 || c.solarMonth != a.solarMonth) {
  398. X.dateArray[e] = null;
  399. continue
  400. }
  401. var b = new U(new Date());
  402. if (c.solarYear == b.solarYear
  403. && c.solarMonth == b.solarMonth
  404. && c.solarDate == b.solarDate) {
  405. c.isToday = true
  406. }
  407. X.dateArray[e] = c;
  408. c = new U(C(c.date, 1));
  409. f--
  410. }
  411. }
  412. return {
  413. init : function(a) {
  414. Z(a)
  415. },
  416. getJson : function() {
  417. return X
  418. }
  419. }
  420. })();
  421. var W = (function() {
  422. var C = M("top").getElementsByTagName("SELECT")[0];
  423. var X = M("top").getElementsByTagName("SELECT")[1];
  424. var G = M("top").getElementsByTagName("SPAN")[0];
  425. var c = M("top").getElementsByTagName("SPAN")[1];
  426. var Y = M("top").getElementsByTagName("INPUT")[0];
  427. function a(g) {
  428. G.innerHTML = g.ganzhiYear;
  429. c.innerHTML = g.shengxiao
  430. }
  431. function b(g) {
  432. C[g.solarYear - 1901].selected = true;
  433. X[g.solarMonth - 1].selected = true
  434. }
  435. function f() {
  436. var j = C.value;
  437. var g = X.value;
  438. var i = new U(new Date(j, g - 1, 1));
  439. Q.init(i);
  440. N.draw();
  441. if (this == C) {
  442. i = new U(new Date(j, 3, 1));
  443. G.innerHTML = i.ganzhiYear;
  444. c.innerHTML = i.shengxiao
  445. }
  446. var h = new U(new Date());
  447. Y.style.visibility = (j == h.solarYear && g == h.solarMonth) ? "hidden"
  448. : "visible"
  449. }
  450. function Z() {
  451. var g = new U(new Date());
  452. a(g);
  453. b(g);
  454. Q.init(g);
  455. N.draw();
  456. Y.style.visibility = "hidden"
  457. }
  458. function d(k, g) {
  459. for ( var j = 1901; j < 2050; j++) {
  460. var h = R("OPTION");
  461. h.value = j;
  462. h.innerHTML = j;
  463. if (j == k) {
  464. h.selected = "selected"
  465. }
  466. C.appendChild(h)
  467. }
  468. for ( var j = 1; j < 13; j++) {
  469. var h = R("OPTION");
  470. h.value = j;
  471. h.innerHTML = j;
  472. if (j == g) {
  473. h.selected = "selected"
  474. }
  475. X.appendChild(h)
  476. }
  477. C.onchange = f;
  478. X.onchange = f
  479. }
  480. function e(g) {
  481. d(g.solarYear, g.solarMonth);
  482. G.innerHTML = g.ganzhiYear;
  483. c.innerHTML = g.shengxiao;
  484. Y.onclick = Z;
  485. Y.style.visibility = "hidden"
  486. }
  487. return {
  488. init : function(g) {
  489. e(g)
  490. },
  491. reset : function(g) {
  492. b(g)
  493. }
  494. }
  495. })();
  496. var N = (function() {
  497. function C() {
  498. var Z = Q.getJson();
  499. var c = Z.dateArray;
  500. M("cm").style.height = Z.lines * 38 + 2 + "px";
  501. M("cm").innerHTML = "";
  502. for ( var a = 0; a < c.length; a++) {
  503. if (c[a] == null) {
  504. continue
  505. }
  506. var X = R("DIV");
  507. if (c[a].isToday) {
  508. X.style.border = "1px solid #a5b9da";
  509. X.style.background = "#c1d9ff"
  510. }
  511. X.className = "cell";
  512. X.style.left = ((a % 7) * 14 + 1) + "%"
  513. X.style.top = Math.floor(a / 7) * 38 + 2 + "px";
  514. var b = R("DIV");
  515. b.className = "so";
  516. b.style.color = ((a % 7) > 5 || (a % 7) < 1 || c[a].isRest) ? "#c60b02"
  517. : "#313131";
  518. b.innerHTML = c[a].solarDate;
  519. X.appendChild(b);
  520. var Y = R("DIV");
  521. Y.style.color = "#666";
  522. Y.innerHTML = c[a].showInLunar;
  523. X.appendChild(Y);
  524. X.onmouseover = (function(d) {
  525. return function(f) {
  526. F.show({
  527. dateIndex : d,
  528. cell : this
  529. })
  530. }
  531. })(a);
  532. X.onmouseout = function() {
  533. F.hide()
  534. };
  535. M("cm").appendChild(X)
  536. }
  537. var G = R("DIV");
  538. G.id = "fd";
  539. M("cm").appendChild(G);
  540. F.init(G)
  541. }
  542. return {
  543. draw : function(G) {
  544. C(G)
  545. }
  546. }
  547. })();
  548. var F = (function() {
  549. var C;
  550. function Y(e, c) {
  551. if (arguments.length > 1) {
  552. var b = /([.*+?^=!:${}()|[\]\/\\])/g, Z = "{".replace(b,
  553. "\\$1"), d = "}".replace(b, "\\$1");
  554. var a = new RegExp("#" + Z + "([^" + Z + d + "]+)" + d, "g");
  555. if (typeof (c) == "object") {
  556. return e.replace(a, function(f, h) {
  557. var g = c[h];
  558. return typeof (g) == "undefined" ? "" : g
  559. })
  560. }
  561. }
  562. return e
  563. }
  564. function G(b) {
  565. var a = Q.getJson().dateArray[b.dateIndex];
  566. var Z = b.cell;
  567. var c = "#{solarYear} 年 #{solarMonth} 月 #{solarDate} 日 #{solarWeekDayInChinese}";
  568. c += "<br><b>农历 #{lunarMonthInChinese}月#{lunarDateInChinese}</b>";
  569. c += "<br>#{ganzhiYear}年 #{ganzhiMonth}月 #{ganzhiDate}日";
  570. if (a.solarFestival != "" || a.lunarFestival != ""
  571. || a.jieqi != "") {
  572. c += "<br><b>#{lunarFestival} #{solarFestival} #{jieqi}</b>"
  573. }
  574. C.innerHTML = Y(c, a);
  575. //C.style.top = Z.offsetTop + Z.offsetHeight - 5 + "px";
  576. //C.style.top = Z.offsetTop + Z.offsetHeight + "px";
  577. C.style.top = document.getElementById("cm").offsetHeight + "px";
  578. //C.style.left = Z.offsetLeft + Z.offsetWidth - 5 + "px";
  579. C.style.left = "20%";
  580. C.style.display = "block";
  581. C.onclick = function() {
  582. this.style.display = "none";
  583. };
  584. }
  585. function X() {
  586. C.style.display = "none"
  587. }
  588. return {
  589. show : function(Z) {
  590. G(Z)
  591. },
  592. hide : function() {
  593. X()
  594. },
  595. init : function(Z) {
  596. C = Z
  597. }
  598. }
  599. })();
  600. var A = new U(new Date());
  601. if (S) {
  602. window.attachEvent("onload", function() {
  603. W.reset(A)
  604. })
  605. }
  606. W.init(A);
  607. Q.init(A);
  608. N.draw();
  609. })();
  610. //-->
  611. </script>