10 lines
12 KiB
JavaScript
10 lines
12 KiB
JavaScript
|
/**
|
|||
|
* 农历(阴历)万年历
|
|||
|
* LunarCalendar;NPM NAME:lunar-calendar
|
|||
|
* vervison : v0.1.4
|
|||
|
* Github : https://github.com/zzyss86/LunarCalendar
|
|||
|
* HomePage : http://www.tuijs.com/
|
|||
|
* Author : JasonZhou
|
|||
|
* Email : zzyss86@qq.com
|
|||
|
*/
|
|||
|
!function(){function a(a){var b=H[a-B];return b[0]}function b(a){for(var b=H[a-B],c=b[0],d=b[3].toString(2),e=d.split(""),f=0;f<16-e.length;f++)e.unshift(0);for(var g=c?13:12,h=0,i=[],f=0;g>f;f++)0==e[f]?(h+=29,i.push(29)):(h+=30,i.push(30));return{yearDays:h,monthDays:i}}function c(a,c){for(var d=b(a),e=c>0?c:d.yearDays-Math.abs(c),f=d.monthDays,g=0,h=0,i=0;i<f.length;i++)if(g+=f[i],g>e){h=i,g-=f[i];break}return[a,h,e-g+1]}function d(a,b,d){var f=H[a-B],g=f[1],h=f[2],i=e(a,g-1,h,a,b,d);if(0==i)return[a,0,1];var j=i>0?a:a-1;return c(j,i)}function e(a,b,c,d,e,f){var g=new Date(a,b,c).getTime(),h=new Date(d,e,f).getTime();return(h-g)/864e5}function f(a,c,d){for(var e=b(a),f=e.monthDays,g=0,h=0;h<f.length&&c>h;h++)g+=f[h];return g+d-1}function g(a,b){var c=new Date(31556925974.7*(a-1890)+6e4*I[b]+Date.UTC(1890,0,5,16,2,31));return c.getUTCDate()}function h(a){for(var b={},c=0,d=0;24>d;d++){var e=g(a,d);d%2==0&&c++,b[A(c-1,e)]=D.solarTerm[d]}return b}function i(a){var b=a-1890+25;return D.zodiac[b%12]}function j(a){return D.heavenlyStems[a%10]+D.earthlyBranches[a%12]}function k(a,b){return b=b||0,j(a-1890+25+b)}function l(a,b,c){return c=c||0,j(12*(a-1890)+b+12+c)}function m(a,b,c){var d=Date.UTC(a,b,c)/864e5+29219+18;return j(d)}function n(a,b){var c=[31,o(a)?29:28,31,30,31,30,31,31,30,31,30,31];return c[b]}function o(a){return a%4==0&&a%100!=0||a%400==0}function p(a,b,c,d){var e=arguments.length,f=new Date;return a=e?parseInt(a,10):f.getFullYear(),b=e?parseInt(b-1,10):f.getMonth(),c=e?parseInt(c,10)||f.getDate():f.getDate(),(d?d:B+1)>a||a>C?{error:100,msg:x[100]}:{year:a,month:b,day:c}}function q(a,b,c){var d=p(a,b,c);if(d.error)return d;var e=d.year,g=d.month,h=d.day,i=f(e,g,h),j=H[e-B],k=j[1],l=j[2],m=new Date(e,k-1,l).getTime()+864e5*i;return m=new Date(m),{year:m.getFullYear(),month:m.getMonth()+1,day:m.getDate()}}function r(c,e,f){var j=p(c,e,f,B);if(j.error)return j;var n=j.year,o=j.month,q=j.day;z.setCurrent(n);var r=z.get("term2")?z.get("term2"):z.set("term2",g(n,2)),s=z.get("termList")?z.get("termList"):z.set("termList",h(n)),t=g(n,2*o),u=o>1||1==o&&q>=r?n+1:n,v=q>=t?o+1:o,w=d(n,o,q),x=a(w[0]),y="";y=x>0&&x==w[1]?"闰"+D.monthCn[w[1]-1]+"月":x>0&&w[1]>x?D.monthCn[w[1]-1]+"月":D.monthCn[w[1]]+"月";var C="",H=b(w[0]).monthDays;C=w[1]==H.length-1&&w[2]==H[H.length-1]?G.d0100:x>0&&w[1]>x?G[A(w[1]-1,w[2])]:G[A(w[1],w[2])];var I={zodiac:i(u),GanZhiYear:k(u),GanZhiMonth:l(n,v),GanZhiDay:m(n,o,q),worktime:E["y"+n]&&E["y"+n][A(o,q)]?E["y"+n][A(o,q)]:0,term:s[A(o,q)],lunarYear:w[0],lunarMonth:w[1]+1,lunarDay:w[2],lunarMonthName:y,lunarDayName:D.dateCn[w[2]-1],lunarLeapMonth:x,solarFestival:F[A(o,q)],lunarFestival:C};return I}function s(a,b,c){var d=p(a,b);if(d.error)return d;for(var e=d.year,f=d.month,g=t(e,f+1,c),h=0;h<g.monthData.length;h++){var i=g.monthData[h],j=r(i.year,i.month,i.day);v(g.monthData[h],j)}return g}function t(a,b,c){var d=p(a,b);if(d.error)return d;var e,f,g,h=d.year,i=d.month,j=new Date(h,i,1),k={firstDay:j.getDay(),monthDays:n(h,i),monthData:[]};if(k.monthData=w(h,i+1,k.monthDays,1),c){if(k.firstDay>0){var l=0>i-1?h-1:h,m=0>i-1?11:i-1;e=n(l,m),f=w(l,m+1,k.firstDay,e-k.firstDay+1),k.monthData=f.concat(k.monthData)}if(42-k.monthData.length!=0){var o=i+1>11?h+1:h,q=i+1>11?0:i+1,r=42-k.monthData.length;g=w(o,q+1,r,1),k.monthData=k.monthData.concat(g)}}return k}function u(a){v(E,a)}var v=function(a,b){if(a&&b&&"object"==typeof b)for(var c in b)a[c]=b[c];return a},w=function(a,b,c,d){var e=[];if(d=d||0,1>c)return e;for(var f=d,g=0;c>g;g++)e.push({year:a,month:b,day:f}),f++;return e},x={100:"输入的年份超过了可查询范围,仅支持1891至2100年",101:"参数输入错误,请查阅文档"},y=null,z={current:"",setCurrent:function(a){this.current!=a&&(this.current=a,this.clear())},set:function(a,b){return y||(y={}),y[a]=b,y[a]},get:function(a){return y||(y={}),y[a]},clear:function(){y=null}},A=function(a,b){return a+=1,a=10>a?"0"+a:a,b=10>b?"0"+b:b,"d"+a+b},B=1890,C=2100,D={heavenlyStems:["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],earthlyBranches:["子","丑","寅","卯","辰",
|