diff --git a/.gitignore b/.gitignore index 476a30b..390eb33 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ node_modules/ package-lock.json run.js +index.js # Thumbnails ._* diff --git a/Readme.md b/Readme.md index f4fe69f..c322d1a 100644 --- a/Readme.md +++ b/Readme.md @@ -9,8 +9,7 @@ 农历的计算, 只支持 1901-2100 范围内的。 -![demo1.png](./img/demo.png) - + ## 安装 ```bash diff --git a/img/demo.png b/img/demo.png index d01993b..42c613f 100644 Binary files a/img/demo.png and b/img/demo.png differ diff --git a/index.js b/index.js index 32aeea5..3a06085 100755 --- a/index.js +++ b/index.js @@ -3,5 +3,5 @@ var v0=Object.create;var q=Object.defineProperty;var C0=Object.getOwnPropertyDes `:` `)+t,n=a+1,a=e.indexOf(` `,n)}while(a!==-1);return l+=e.slice(n),l}var{stdout:n0,stderr:l0}=t0,P=Symbol("GENERATOR"),R=Symbol("STYLER"),M=Symbol("IS_EMPTY"),s0=["ansi","ansi","ansi256","ansi16m"],S=Object.create(null),w0=(e,r={})=>{if(r.level&&!(Number.isInteger(r.level)&&r.level>=0&&r.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let t=n0?n0.level:0;e.level=r.level===void 0?t:r.level};var Y0=e=>{let r=(...t)=>t.join(" ");return w0(r,e),Object.setPrototypeOf(r,_.prototype),r};function _(e){return Y0(e)}Object.setPrototypeOf(_.prototype,Function.prototype);for(let[e,r]of Object.entries(T))S[e]={get(){let t=Y(this,G(r.open,r.close,this[R]),this[M]);return Object.defineProperty(this,e,{value:t}),t}};S.visible={get(){let e=Y(this,this[R],!0);return Object.defineProperty(this,"visible",{value:e}),e}};var V=(e,r,t,...a)=>e==="rgb"?r==="ansi16m"?T[t].ansi16m(...a):r==="ansi256"?T[t].ansi256(T.rgbToAnsi256(...a)):T[t].ansi(T.rgbToAnsi(...a)):e==="hex"?V("rgb",r,t,...T.hexToRgb(...a)):T[t][e](...a),D0=["rgb","hex","ansi256"];for(let e of D0){S[e]={get(){let{level:t}=this;return function(...a){let n=G(V(e,s0[t],"color",...a),T.color.close,this[R]);return Y(this,n,this[M])}}};let r="bg"+e[0].toUpperCase()+e.slice(1);S[r]={get(){let{level:t}=this;return function(...a){let n=G(V(e,s0[t],"bgColor",...a),T.bgColor.close,this[R]);return Y(this,n,this[M])}}}}var j0=Object.defineProperties(()=>{},{...S,level:{enumerable:!0,get(){return this[P].level},set(e){this[P].level=e}}}),G=(e,r,t)=>{let a,n;return t===void 0?(a=e,n=r):(a=t.openAll+e,n=r+t.closeAll),{open:e,close:r,openAll:a,closeAll:n,parent:t}},Y=(e,r,t)=>{let a=(...n)=>$0(a,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(a,j0),a[P]=e,a[R]=r,a[M]=t,a},$0=(e,r)=>{if(e.level<=0||!r)return e[M]?"":r;let t=e[R];if(t===void 0)return r;let{openAll:a,closeAll:n}=t;if(r.includes("\x1B"))for(;t!==void 0;)r=o0(r,t.close,t.open),t=t.parent;let l=r.indexOf(` -`);return l!==-1&&(r=a0(r,n,a,l)),a+r+n};Object.defineProperties(_.prototype,S);var P0=_(),i2=_({level:l0?l0.level:0});var i=P0;var i0=require("path"),D=[19416,19168,42352,21717,53856,55632,91476,22176,39632,21970,19168,42422,42192,53840,119381,46400,54944,44450,38320,84343,18800,42160,46261,27216,27968,109396,11104,38256,21234,18800,25958,54432,59984,92821,23248,11104,100067,37600,116951,51536,54432,120998,46416,22176,107956,9680,37584,53938,43344,46423,27808,46416,86869,19872,42416,83315,21168,43432,59728,27296,44710,43856,19296,43748,42352,21088,62051,55632,23383,22176,38608,19925,19152,42192,54484,53840,54616,46400,46752,103846,38320,18864,43380,42160,45690,27216,27968,44870,43872,38256,19189,18800,25776,29859,59984,27480,23232,43872,38613,37600,51552,55636,54432,55888,30034,22176,43959,9680,37584,51893,43344,46240,47780,44368,21977,19360,42416,86390,21168,43312,31060,27296,44368,23378,19296,42726,42208,53856,60005,54576,23200,30371,38608,19195,19152,42192,118966,53840,54560,56645,46496,22224,21938,18864,42359,42160,43600,111189,27936,44448,84835,37744,18936,18800,25776,92326,59984,27424,108228,43744,37600,53987,51552,54615,54432,55888,23893,22176,42704,21972,21200,43448,43344,46240,46758,44368,21920,43940,42416,21168,45683,26928,29495,27296,44368,84821,19296,42352,21732,53600,59752,54560,55968,92838,22224,19168,43476,41680,53584,62034,54560],c0=["\u6B63","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D","\u5341","\u51AC","\u814A"],A={0:"\u521D",1:"\u4E00",2:"\u4E8C",3:"\u4E09",4:"\u56DB",5:"\u4E94",6:"\u516D",7:"\u4E03",8:"\u516B",9:"\u4E5D",10:"\u5341",20:"\u5EFF"},x0=["\u9F20","\u725B","\u864E","\u5154","\u9F99","\u86C7","\u9A6C","\u7F8A","\u7334","\u9E21","\u72D7","\u732A"],u0=["\u7532","\u4E59","\u4E19","\u4E01","\u620A","\u5DF1","\u5E9A","\u8F9B","\u58EC","\u7678"],f0=["\u5B50","\u4E11","\u5BC5","\u536F","\u8FB0","\u5DF3","\u5348","\u672A","\u7533","\u9149","\u620C","\u4EA5"],H=["\u5C0F\u5BD2","\u5927\u5BD2","\u7ACB\u6625","\u96E8\u6C34","\u60CA\u86F0","\u6625\u5206","\u6E05\u660E","\u8C37\u96E8","\u7ACB\u590F","\u5C0F\u6EE1","\u8292\u79CD","\u590F\u81F3","\u5C0F\u6691","\u5927\u6691","\u7ACB\u79CB","\u5904\u6691","\u767D\u9732","\u79CB\u5206","\u5BD2\u9732","\u971C\u964D","\u7ACB\u51AC","\u5C0F\u96EA","\u5927\u96EA","\u51AC\u81F3"],d0=["062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220722082408240824092408230823","062105200722062107220722082409240924092408230823","072105200621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200722062107220722082409240924092408230823","072105200621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200722062107220722082409240924092408230823","072105200621052006210622072308230823092408220722","062004190621052106220622082308240823092408230822","062104190621052106220622082408240824092408230823","062105200622062106220722082408240924092408230823","062105200621052006210622072308230823082408220722","062004190621052106210622082308240823092408230822","062104190621052106220622082408240824092408230822","062105200622062106220722082408240924092408230823","062105200621052006210622072308230823082408220722","062004190621052006210622082308240823092408230722","062104190621052106220622082408240824092408230822","062105190621062106220722082408240924092408230823","062105200621052006210622072308230823082408220722","062004190621052006210622082308240823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220722082408240924092408230823","062105200621052006210622072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220722082408240824092408230823","062105200621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200621052005210621072308230823082307220722","062004190621052006210622072308230823082408220722","062004190621052106220622082308240823092408230822","062104190621052106220622082408240824092408230823","062105200521052005210621072307230823082307220722","052004190621052006210622072308230823082408220722","062004190621052006210622082308240823092408230822","062104190621052106220622082408240824092408230823","062105200521052005210621072307230823082307220722","052004190621052006210622072308230823082408220722","062004190621052006210622082308240823092408230722","062104190621052106220622082308240824092408230822","062105200520052005210621072307230823082307220722","052004190621052006210622072308230823082408220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190520052005210621072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190520052005210621072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190520052005210521072307230723082307220722","052004190621052005210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240823092408230822","062105190520042005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823082408230722","062004190621052106210622082308240823092408230822","062105190520042005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823082408220722","062004190621052006210622082308240823092408230822","062104190520042005210521072207230723082307220722","052004190521052005210621072307230823082307220722","052004190621052006210622072308230823082408220722","062004190621052006210622072308240823092408230722","062104190520042005210521072207230723082307220721","052004190520052005210621072307230723082307220722","052004190621052006210621072308230823082408220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230723082307220721","052004180520052005210621072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230722082307220721","052004180520042005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823082408230722","062104190520042005200521072207230722082307220721","052004180520042005210521072207230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823082408220722","062004190520041905200521072207230722082307220721","052003180520042005210521072207230723082307220722","052004190521052005210621072307230823082307220722","052004190621052006210621072308230823082408220722","062004190520041905200521062207220722082307220721","052003180520042005210521072207230723082307220721","052004190520052005210621072307230723082307220722","052004190621052006210621072308230823082408220722","062004190520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190520041905200521062207220722082307220621","052003180520042005200521072207230722082307220721","052004180520042005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190520041905200521062207220722072307220621","052003180520041905200521072207230722082307220721","052004180520042005210521072207230723082307220722","052004190621052005210621072307230823082307220722","062004190520041905200520062207220722072307210621","051903180520041905200521062207220722082307220721","052003180520042005210521072207230723082307220722","052004190520052005210621072307230723082307220722","052004190520041905200520062207220722072307210621","051903180520041905200521062207220722082307220721","052003180520042005210521072207230723082307220722","052004190520052005210521072307230723082307220722","052004190520041905200520062207220722072307210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004190520052005210521072307230723082307220722","052004190520041905200520062207220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190520041905200520062207220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190520041904200520062206220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005200521072207230722082307220721","052004180520052005210521072307230723082307220722","052004190520041904200520062206220722072206210621","051903180520041905200521062207220722072307220621","052003180520042005200521072207230722082307220721","052004180520042005210521072207230723082307220722","052004190520041904200520062206220722072206210621","051903180520041905200521062207220722072307220621","052003180520041905200521062207230722082307220721","052004180520042005210521072207230723082307220722","052004190520041904200520062206220722072206210621","051903180520041905200520062207220722072307210621","052003180520041905200521062207220722082307220721","052003180520042005210521072207230723082307220722","052004190419041904200520062206220622072206210621","041903180520041905200520062207220722072307210621","051903180520041905200521062207220722082307220721","052003180520042005210521072207230723082307220722","052004190419041904200420062206220622072206210621","041903180520041905200520062207220722072307210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004190419041904200420062206220622072206210621","041903180520041905200520062207220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180419041904200420062206220622072206210621","041903180520041905200520062206220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722"],I={"1.1":"\u6625\u8282","1.15":"\u5143\u5BB5\u8282","2.2":"\u9F99\u62AC\u5934","3.3":"\u4E0A\u5DF3\u8282","5.5":"\u7AEF\u5348\u8282","7.7":"\u4E03\u5915\u8282","7.15":"\u4E2D\u5143\u8282","8.15":"\u4E2D\u79CB\u8282","9.9":"\u91CD\u9633\u8282","10.1":"\u5BD2\u8863\u8282","10.15":"\u4E0B\u5143\u8282","12.8":"\u814A\u516B\u8282","12.23":"\u5317\u65B9\u5C0F\u5E74","12.24":"\u5357\u65B9\u5C0F\u5E74","12.30":"\u9664\u5915"},b0={"1.1":"\u5143\u65E6","2.14":"\u60C5\u4EBA\u8282","3.8":"\u5987\u5973\u8282","3.12":"\u690D\u6811\u8282","4.1":"\u611A\u4EBA\u8282","5.1":"\u52B3\u52A8\u8282","5.4":"\u9752\u5E74\u8282","5.12":"\u62A4\u58EB\u8282","6.1":"\u513F\u7AE5\u8282","7.1":"\u5EFA\u515A\u8282","8.1":"\u5EFA\u519B\u8282","9.10":"\u6559\u5E08\u8282","10.1":"\u56FD\u5E86\u8282","12.24":"\u5E73\u5B89\u591C","12.25":"\u5723\u8BDE\u8282"},B=(0,i0.join)(process.env.HOME||process.env.LOCALAPPDATA,".festivals.json");var U=L(require("fs"));var p0={};if(U.default.existsSync(B))try{p0=JSON.parse(U.default.readFileSync(B))}catch{}function j(e=1901,r=0,t=1){var a=Date.UTC(1900,0,31),n=Date.UTC(e,r,t),l=(n-a)/(24*60*60*1e3)+1,s,d,o={short:"",solarTerms:"",festival:"",lunarFestival:""},m=d0[e-1900],h=`${e}.${r+1}.${t}`;if(e<1901||e>2100)return o;for(let c=1900;c<=2100;c++){let u=V0(c);if(l-=u,l<=0){o.year=c,l+=u;break}}s=g0(o.year),d=K(o.year);for(let c=0;c0&&c>=d&&(o.leap=c===d,o.month-=1);break}if(o.custom=p0[h]||"",m){let c=m.slice(r*4,(r+1)*4);+c.slice(0,2)===t?o.solarTerms=H[r*2]:+c.slice(2)===t&&(o.solarTerms=H[r*2+1])}return o.festival=b0[`${r+1}.${t}`]||"",o.leap||(o.month===11&&o.day===s.pop()?(o.festival=I["12.30"],o.lunarFestival=I["12.30"]):(o.festival=I[`${o.month+1}.${o.day}`]||o.festival,o.lunarFestival=I[`${o.month+1}.${o.day}`]||"")),o.yearCN=W(o.year),o.monthCN=(o.leap>0?"\u95F0":"")+c0[o.month]+"\u6708",o.day<11?o.dayCN=A[0]+A[o.day]:o.day<20?o.dayCN=A[10]+A[o.day-10]:o.day===20?o.dayCN=A[2]+A[10]:o.day<30?o.dayCN=A[20]+A[o.day-20]:o.day===30&&(o.dayCN=A[3]+A[10]),o.short=o.festival?o.festival:o.solarTerms?o.solarTerms:o.day===1?o.monthCN:o.dayCN,o}function V0(e){var r=g0(e);return r.reduce((t,a)=>t+=a,0)}function K(e){var r=D[e-1900];return r&15}function G0(e){var r=D[e-1900],t=K(e);return t>0?r&983040?30:29:0}function g0(e){var r=D[e-1900],t=K(e),a=G0(e),n=[];for(let l=32768;l>8;l>>=1)n.push(r&l?30:29);return t>0&&n.splice(t,0,a),n}function W(e){var r=(e-3)%10,t=(e-3)%12;return r=r===0?10:r,t=t===0?12:t,u0[r-1]+f0[t-1]+x0[(e-4)%12]+"\u5E74"}var H0=["\u65E5","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D"].map((e,r)=>(e="\u661F\u671F"+e,(r===0||r===6)&&(e=i.red(e))," "+e+" "+i.grey("\u2502"))),N=i.grey("\u2502"),U0=i.grey("\u251C"),K0=i.grey("\u2514"),p2=i.grey("\u2502"+(" ".repeat(10)+"\u2502").repeat(7));function y0(){var e=new Date;return[e.getFullYear(),e.getMonth()]}function h0(e,r){return new Date(e,r+1,0).getDate()}function m0(e,r,t){return new Date(e,r,t||1).getDay()}function W0({year:e,month:r,day:t},a){return a.year===e&&a.month===r&&a.day===t}function J0(){var e=new Date;return{year:e.getFullYear(),month:e.getMonth(),day:e.getDate()}}function Z0(e,r){var t=h0(e,r-1),a=h0(e,r),n=1-m0(e,r),l=0,s=J0(),d=[],o,m,h,c;n<1&&(o=e,m=r-1,m<0&&(m=11,o--));for(let u=n;u<=a;u++){let v={day:u<1?t- -u:(u+"").padStart(2,"0")},E;if(u>0){let Z=m0(e,r,u);E=j(e,r,u),v.weekend=Z===0||Z===6,v.picked=!!W0({year:e,month:r,day:u},s),v.highlight=!!E.festival||!!E.solarTerms}else E=j(o,m,t+u),v.grey=1;v.lunar=E.short,v.custom=E.custom,d.push(v)}l=d.length%7,l=l>0?7-l:0,l>0&&(h=e,c=r+1,c>11&&(c=0,h++));for(let u=1;u<=l;u++){let v=j(h,c,u);d.push({day:(u+"").padStart(2,"0"),lunar:v.short,custom:v.custom,grey:1})}return d}function q0(e,r){var t=`${e}\u5E74${r+1}\u6708${" ".repeat(10)}${W(e,r)}`;t=i.grey("\u2502 ")+i.cyan(t)+" ".repeat(71-t.length-2)+i.grey("\u2502"),console.log(i.grey("\u250C\u2500"+"\u2500".repeat(75)+"\u2510")),console.log(i.grey("\u2502"+" ".repeat(76)+"\u2502")),console.log(t),console.log(i.grey("\u2502"+" ".repeat(76)+"\u2502")),console.log(i.grey("\u251C"+"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C".repeat(7).slice(0,-1)+"\u2524")),console.log(i.grey("\u2502")+H0.join("")),console.log(i.grey("\u251C"+"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C".repeat(7).slice(0,-1)+"\u2524"))}function z0(e,r){var t=Z0(e,r),a=0,n=3*Math.ceil(t.length/7);for(let l=0;l=0?c=" ".repeat(h):u=u.slice(0,h),o.picked?s+=u+i.bgBlue.white(c+o.lunar+c)+u+N:o.lunar?(o.lunar=o.highlight?i.cyan(o.lunar):o.weekend?i.redBright(o.lunar):i.grey(o.lunar),s+=" ".repeat(h+2)+o.lunar+" ".repeat(h+2)+N):s+=" ".repeat(h*2)+N;break}}s&&console.log(s)}}function O(e,r){q0(e,r),z0(e,r)}var A0="1.2.7",C=process.argv.slice(2),F=C.shift(),[g,p]=y0();function J(e){for(let r=0;r<12;r++)O(e,r),r<11&&console.log("")}function b(...e){e[0]=e[0].padEnd(20," "),e.length>1&&e.splice(1,0," - "),console.log.apply(null,e)}function Q0(){b("=".repeat(64)),b(`\u7EC8\u7AEF\u7248\u4E07\u5E74\u5386 v${A0}, \u4F5C\u8005: \u5B87\u5929`),b("=".repeat(64)),b("\u7528\u6CD5: cal [command] args..."),b("Commands:"),b(" -y {year}","\u6253\u5370\u6307\u5B9A\u5E74\u4EFD\u7684\u65E5\u5386"),b(" -m","\u6253\u5370\u6307\u5B9A\u6708\u4EFD\u7684\u65E5\u5386"),b(" -c","\u5BFC\u5165\u81EA\u5B9A\u4E49\u4F11\u5047\u65E5, \u5FC5\u987B\u662F\u6807\u51C6json\u683C\u5F0F, \u8BED\u6CD5\u770B\u4E0B\u9762\u7684\u793A\u4F8B"),b(" -h","\u67E5\u770B\u5E2E\u52A9\u6587\u6863"),b(" -v",`\u67E5\u770B\u7A0B\u5E8F\u7684\u7248\u672C +`);return l!==-1&&(r=a0(r,n,a,l)),a+r+n};Object.defineProperties(_.prototype,S);var P0=_(),i2=_({level:l0?l0.level:0});var i=P0;var i0=require("path"),D=[19416,19168,42352,21717,53856,55632,91476,22176,39632,21970,19168,42422,42192,53840,119381,46400,54944,44450,38320,84343,18800,42160,46261,27216,27968,109396,11104,38256,21234,18800,25958,54432,59984,92821,23248,11104,100067,37600,116951,51536,54432,120998,46416,22176,107956,9680,37584,53938,43344,46423,27808,46416,86869,19872,42416,83315,21168,43432,59728,27296,44710,43856,19296,43748,42352,21088,62051,55632,23383,22176,38608,19925,19152,42192,54484,53840,54616,46400,46752,103846,38320,18864,43380,42160,45690,27216,27968,44870,43872,38256,19189,18800,25776,29859,59984,27480,23232,43872,38613,37600,51552,55636,54432,55888,30034,22176,43959,9680,37584,51893,43344,46240,47780,44368,21977,19360,42416,86390,21168,43312,31060,27296,44368,23378,19296,42726,42208,53856,60005,54576,23200,30371,38608,19195,19152,42192,118966,53840,54560,56645,46496,22224,21938,18864,42359,42160,43600,111189,27936,44448,84835,37744,18936,18800,25776,92326,59984,27424,108228,43744,37600,53987,51552,54615,54432,55888,23893,22176,42704,21972,21200,43448,43344,46240,46758,44368,21920,43940,42416,21168,45683,26928,29495,27296,44368,84821,19296,42352,21732,53600,59752,54560,55968,92838,22224,19168,43476,41680,53584,62034,54560],c0=["\u6B63","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D","\u5341","\u51AC","\u814A"],A={0:"\u521D",1:"\u4E00",2:"\u4E8C",3:"\u4E09",4:"\u56DB",5:"\u4E94",6:"\u516D",7:"\u4E03",8:"\u516B",9:"\u4E5D",10:"\u5341",20:"\u5EFF"},x0=["\u9F20","\u725B","\u864E","\u5154","\u9F99","\u86C7","\u9A6C","\u7F8A","\u7334","\u9E21","\u72D7","\u732A"],u0=["\u7532","\u4E59","\u4E19","\u4E01","\u620A","\u5DF1","\u5E9A","\u8F9B","\u58EC","\u7678"],f0=["\u5B50","\u4E11","\u5BC5","\u536F","\u8FB0","\u5DF3","\u5348","\u672A","\u7533","\u9149","\u620C","\u4EA5"],H=["\u5C0F\u5BD2","\u5927\u5BD2","\u7ACB\u6625","\u96E8\u6C34","\u60CA\u86F0","\u6625\u5206","\u6E05\u660E","\u8C37\u96E8","\u7ACB\u590F","\u5C0F\u6EE1","\u8292\u79CD","\u590F\u81F3","\u5C0F\u6691","\u5927\u6691","\u7ACB\u79CB","\u5904\u6691","\u767D\u9732","\u79CB\u5206","\u5BD2\u9732","\u971C\u964D","\u7ACB\u51AC","\u5C0F\u96EA","\u5927\u96EA","\u51AC\u81F3"],d0=["062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220722082408240824092408230823","062105200722062107220722082409240924092408230823","072105200621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200722062107220722082409240924092408230823","072105200621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200722062107220722082409240924092408230823","072105200621052006210622072308230823092408220722","062004190621052106220622082308240823092408230822","062104190621052106220622082408240824092408230823","062105200622062106220722082408240924092408230823","062105200621052006210622072308230823082408220722","062004190621052106210622082308240823092408230822","062104190621052106220622082408240824092408230822","062105200622062106220722082408240924092408230823","062105200621052006210622072308230823082408220722","062004190621052006210622082308240823092408230722","062104190621052106220622082408240824092408230822","062105190621062106220722082408240924092408230823","062105200621052006210622072308230823082408220722","062004190621052006210622082308240823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220722082408240924092408230823","062105200621052006210622072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220722082408240824092408230823","062105200621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190621062106220622082408240824092408230823","062105200621052005210621072308230823082307220722","062004190621052006210622072308230823082408220722","062004190621052106220622082308240823092408230822","062104190621052106220622082408240824092408230823","062105200521052005210621072307230823082307220722","052004190621052006210622072308230823082408220722","062004190621052006210622082308240823092408230822","062104190621052106220622082408240824092408230823","062105200521052005210621072307230823082307220722","052004190621052006210622072308230823082408220722","062004190621052006210622082308240823092408230722","062104190621052106220622082308240824092408230822","062105200520052005210621072307230823082307220722","052004190621052006210622072308230823082408220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190520052005210621072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190520052005210621072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240824092408230822","062105190520052005210521072307230723082307220722","052004190621052005210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190621052106220622082308240823092408230822","062105190520042005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823082408230722","062004190621052106210622082308240823092408230822","062105190520042005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823082408220722","062004190621052006210622082308240823092408230822","062104190520042005210521072207230723082307220722","052004190521052005210621072307230823082307220722","052004190621052006210622072308230823082408220722","062004190621052006210622072308240823092408230722","062104190520042005210521072207230723082307220721","052004190520052005210621072307230723082307220722","052004190621052006210621072308230823082408220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230723082307220721","052004180520052005210621072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823092408230722","062104190520042005210521072207230722082307220721","052004180520042005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823082408230722","062104190520042005200521072207230722082307220721","052004180520042005210521072207230723082307220722","052004190621052005210621072307230823082307220722","062004190621052006210622072308230823082408220722","062004190520041905200521072207230722082307220721","052003180520042005210521072207230723082307220722","052004190521052005210621072307230823082307220722","052004190621052006210621072308230823082408220722","062004190520041905200521062207220722082307220721","052003180520042005210521072207230723082307220721","052004190520052005210621072307230723082307220722","052004190621052006210621072308230823082408220722","062004190520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052006210621072308230823082307220722","062004190520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190520041905200521062207220722082307220621","052003180520042005200521072207230722082307220721","052004180520042005210521072307230723082307220722","052004190621052005210621072307230823082307220722","062004190520041905200521062207220722072307220621","052003180520041905200521072207230722082307220721","052004180520042005210521072207230723082307220722","052004190621052005210621072307230823082307220722","062004190520041905200520062207220722072307210621","051903180520041905200521062207220722082307220721","052003180520042005210521072207230723082307220722","052004190520052005210621072307230723082307220722","052004190520041905200520062207220722072307210621","051903180520041905200521062207220722082307220721","052003180520042005210521072207230723082307220722","052004190520052005210521072307230723082307220722","052004190520041905200520062207220722072307210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004190520052005210521072307230723082307220722","052004190520041905200520062207220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190520041905200520062207220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722","052004190520041904200520062206220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005200521072207230722082307220721","052004180520052005210521072307230723082307220722","052004190520041904200520062206220722072206210621","051903180520041905200521062207220722072307220621","052003180520042005200521072207230722082307220721","052004180520042005210521072207230723082307220722","052004190520041904200520062206220722072206210621","051903180520041905200521062207220722072307220621","052003180520041905200521062207230722082307220721","052004180520042005210521072207230723082307220722","052004190520041904200520062206220722072206210621","051903180520041905200520062207220722072307210621","052003180520041905200521062207220722082307220721","052003180520042005210521072207230723082307220722","052004190419041904200520062206220622072206210621","041903180520041905200520062207220722072307210621","051903180520041905200521062207220722082307220721","052003180520042005210521072207230723082307220722","052004190419041904200420062206220622072206210621","041903180520041905200520062207220722072307210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004190419041904200420062206220622072206210621","041903180520041905200520062207220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180419041904200420062206220622072206210621","041903180520041905200520062206220722072206210621","051903180520041905200521062207220722082307220621","052003180520042005210521072207230723082307220721","052004180520052005210521072307230723082307220722"],I={"1.1":"\u6625\u8282","1.15":"\u5143\u5BB5\u8282","2.2":"\u9F99\u62AC\u5934","3.3":"\u4E0A\u5DF3\u8282","5.5":"\u7AEF\u5348\u8282","7.7":"\u4E03\u5915\u8282","7.15":"\u4E2D\u5143\u8282","8.15":"\u4E2D\u79CB\u8282","9.9":"\u91CD\u9633\u8282","10.1":"\u5BD2\u8863\u8282","10.15":"\u4E0B\u5143\u8282","12.8":"\u814A\u516B\u8282","12.23":"\u5317\u65B9\u5C0F\u5E74","12.24":"\u5357\u65B9\u5C0F\u5E74","12.30":"\u9664\u5915"},b0={"1.1":"\u5143\u65E6","2.14":"\u60C5\u4EBA\u8282","3.8":"\u5987\u5973\u8282","3.12":"\u690D\u6811\u8282","4.1":"\u611A\u4EBA\u8282","5.1":"\u52B3\u52A8\u8282","5.4":"\u9752\u5E74\u8282","5.12":"\u62A4\u58EB\u8282","6.1":"\u513F\u7AE5\u8282","7.1":"\u5EFA\u515A\u8282","8.1":"\u5EFA\u519B\u8282","9.10":"\u6559\u5E08\u8282","10.1":"\u56FD\u5E86\u8282","12.24":"\u5E73\u5B89\u591C","12.25":"\u5723\u8BDE\u8282"},B=(0,i0.join)(process.env.HOME||process.env.LOCALAPPDATA,".festivals.json");var U=L(require("fs"));var p0={};if(U.default.existsSync(B))try{p0=JSON.parse(U.default.readFileSync(B))}catch{}function j(e=1901,r=0,t=1){var a=Date.UTC(1900,0,31),n=Date.UTC(e,r,t),l=(n-a)/(24*60*60*1e3)+1,s,d,o={short:"",solarTerms:"",festival:"",lunarFestival:""},m=d0[e-1900],h=`${e}.${r+1}.${t}`;if(e<1901||e>2100)return o;for(let c=1900;c<=2100;c++){let u=V0(c);if(l-=u,l<=0){o.year=c,l+=u;break}}s=g0(o.year),d=K(o.year);for(let c=0;c0&&c>=d&&(o.leap=c===d,o.month-=1);break}if(o.custom=p0[h]||"",m){let c=m.slice(r*4,(r+1)*4);+c.slice(0,2)===t?o.solarTerms=H[r*2]:+c.slice(2)===t&&(o.solarTerms=H[r*2+1])}return o.festival=b0[`${r+1}.${t}`]||"",o.leap||(o.month===11&&o.day===s.pop()?(o.festival=I["12.30"],o.lunarFestival=I["12.30"]):(o.festival=I[`${o.month+1}.${o.day}`]||o.festival,o.lunarFestival=I[`${o.month+1}.${o.day}`]||"")),o.yearCN=W(o.year),o.monthCN=(o.leap>0?"\u95F0":"")+c0[o.month]+"\u6708",o.day<11?o.dayCN=A[0]+A[o.day]:o.day<20?o.dayCN=A[10]+A[o.day-10]:o.day===20?o.dayCN=A[2]+A[10]:o.day<30?o.dayCN=A[20]+A[o.day-20]:o.day===30&&(o.dayCN=A[3]+A[10]),o.short=o.festival?o.festival:o.solarTerms?o.solarTerms:o.day===1?o.monthCN:o.dayCN,o}function V0(e){var r=g0(e);return r.reduce((t,a)=>t+=a,0)}function K(e){var r=D[e-1900];return r&15}function G0(e){var r=D[e-1900],t=K(e);return t>0?r&983040?30:29:0}function g0(e){var r=D[e-1900],t=K(e),a=G0(e),n=[];for(let l=32768;l>8;l>>=1)n.push(r&l?30:29);return t>0&&n.splice(t,0,a),n}function W(e){var r=(e-3)%10,t=(e-3)%12;return r=r===0?10:r,t=t===0?12:t,u0[r-1]+f0[t-1]+x0[(e-4)%12]+"\u5E74"}var H0=["\u65E5","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D"].map((e,r)=>(e="\u661F\u671F"+e,(r===0||r===6)&&(e=i.red(e))," "+e+" "+i.grey("\u2502"))),N=i.grey("\u2502"),U0=i.grey("\u251C"),K0=i.grey("\u2514"),p2=i.grey("\u2502"+(" ".repeat(10)+"\u2502").repeat(7));function y0(){var e=new Date;return[e.getFullYear(),e.getMonth()]}function h0(e,r){return new Date(e,r+1,0).getDate()}function m0(e,r,t){return new Date(e,r,t||1).getDay()}function W0({year:e,month:r,day:t},a){return a.year===e&&a.month===r&&a.day===t}function J0(){var e=new Date;return{year:e.getFullYear(),month:e.getMonth(),day:e.getDate()}}function Z0(e,r){var t=h0(e,r-1),a=h0(e,r),n=1-m0(e,r),l=0,s=J0(),d=[],o,m,h,c;n<1&&(o=e,m=r-1,m<0&&(m=11,o--));for(let u=n;u<=a;u++){let v={day:u<1?t- -u:(u+"").padStart(2,"0")},E;if(u>0){let Z=m0(e,r,u);E=j(e,r,u),v.weekend=Z===0||Z===6,v.picked=!!W0({year:e,month:r,day:u},s),v.highlight=!!E.festival||!!E.solarTerms}else E=j(o,m,t+u),v.grey=1;v.lunar=E.short,v.custom=E.custom,d.push(v)}l=42-d.length,l>0&&(h=e,c=r+1,c>11&&(c=0,h++));for(let u=1;u<=l;u++){let v=j(h,c,u);d.push({day:(u+"").padStart(2,"0"),lunar:v.short,custom:v.custom,grey:1})}return d}function q0(e,r){var t=`${e}\u5E74${r+1}\u6708${" ".repeat(10)}${W(e,r)}`;t=i.grey("\u2502 ")+i.cyan(t)+" ".repeat(71-t.length-2)+i.grey("\u2502"),console.log(i.grey("\u250C\u2500"+"\u2500".repeat(75)+"\u2510")),console.log(i.grey("\u2502"+" ".repeat(76)+"\u2502")),console.log(t),console.log(i.grey("\u2502"+" ".repeat(76)+"\u2502")),console.log(i.grey("\u251C"+"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C".repeat(7).slice(0,-1)+"\u2524")),console.log(i.grey("\u2502")+H0.join("")),console.log(i.grey("\u251C"+"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C".repeat(7).slice(0,-1)+"\u2524"))}function z0(e,r){var t=Z0(e,r),a=0,n=3*Math.ceil(t.length/7);for(let l=0;l=0?c=" ".repeat(h):u=u.slice(0,h),o.picked?s+=u+i.bgBlue.white(c+o.lunar+c)+u+N:o.lunar?(o.lunar=o.highlight?i.cyan(o.lunar):o.weekend?i.redBright(o.lunar):i.grey(o.lunar),s+=" ".repeat(h+2)+o.lunar+" ".repeat(h+2)+N):s+=" ".repeat(h*2)+N;break}}s&&console.log(s)}}function O(e,r){q0(e,r),z0(e,r)}var A0="1.2.7",C=process.argv.slice(2),F=C.shift(),[g,p]=y0();function J(e){for(let r=0;r<12;r++)O(e,r),r<11&&console.log("")}function b(...e){e[0]=e[0].padEnd(20," "),e.length>1&&e.splice(1,0," - "),console.log.apply(null,e)}function Q0(){b("=".repeat(64)),b(`\u7EC8\u7AEF\u7248\u4E07\u5E74\u5386 v${A0}, \u4F5C\u8005: \u5B87\u5929`),b("=".repeat(64)),b("\u7528\u6CD5: cal [command] args..."),b("Commands:"),b(" -y {year}","\u6253\u5370\u6307\u5B9A\u5E74\u4EFD\u7684\u65E5\u5386"),b(" -m","\u6253\u5370\u6307\u5B9A\u6708\u4EFD\u7684\u65E5\u5386"),b(" -c","\u5BFC\u5165\u81EA\u5B9A\u4E49\u4F11\u5047\u65E5, \u5FC5\u987B\u662F\u6807\u51C6json\u683C\u5F0F, \u8BED\u6CD5\u770B\u4E0B\u9762\u7684\u793A\u4F8B"),b(" -h","\u67E5\u770B\u5E2E\u52A9\u6587\u6863"),b(" -v",`\u67E5\u770B\u7A0B\u5E8F\u7684\u7248\u672C `),b("\u793A\u4F8B: "),b(" cal "+i.grey("# \u4E0D\u5E26\u53C2\u6570\u6253\u5370\u5F53\u524D\u5E74\u6708")),b(" cal -y "+i.grey("# -y \u4E0D\u63A5\u53C2\u6570, \u6253\u5370\u5F53\u524D\u5E74\u7684\u6240\u6709\u6708\u4EFD")),b(" cal -y 2000 "+i.grey("# \u6253\u5370\u6307\u5B9A\u5E74\u4EFD\u7684\u6240\u6709\u6708\u4EFD")),b(" cal -y 2021 5 "+i.grey("# \u6253\u5370\u6307\u5B9A\u5E74\u4EFD, \u6307\u5B9A\u6708\u4EFD")),b(" cal -y 2000 -m 3 "+i.grey("# \u540C\u4E0A")),b(" cal -m 5 "+i.grey("# \u6253\u5370\u5F53\u524D\u5E74\u4EFD\u7684 \u6307\u5B9A\u6708\u4EFD")),b(' cal -c {"2021.12.11":"\u73ED","2021.12.12":"\u4F11"} '+i.grey("# \u5BFC\u5165\u81EA\u5B9A\u4E49\u4F11\u5047\u65E5")),process.exit()}switch(F){case"-y":switch(C.length){case 0:J(g);break;case 1:case 2:g=+C.shift(),p=+C.shift(),g===g?p<13&&p>0?O(g,p-1):J(g):console.log("-y \u53C2\u6570\u5F02\u5E38");break;case 3:g=+C.shift(),F=C.shift(),p=+C.pop(),F==="-m"&&p<13&&p>0?O(g,p-1):console.log("-m \u53C2\u6570\u5F02\u5E38");break;default:console.log("-y \u53C2\u6570\u5F02\u5E38");break}break;case"-m":p=+C.shift(),p<13&&p>0?O(g,p-1):console.log("-m \u53C2\u6570\u5F02\u5E38");break;case"-v":b(A0);break;case"-h":Q0();break;case"-c":let e=C.shift();if(e)try{JSON.parse(e),T0.default.writeFileSync(B,e),console.log("\u5BFC\u5165\u6210\u529F")}catch{console.log("\u9519\u8BEF\u7684json\u6570\u636E")}else console.log("\u5BFC\u5165\u7684\u6570\u636E\u4E3A\u7A7A");break;default:F?(g=+F,p=+C.shift(),g===g?p<13&&p>0?O(g,p-1):J(g):console.log("\u53C2\u6570\u5F02\u5E38")):O(g,p);break}process.exit(); diff --git a/src/calendar.js b/src/calendar.js index 5549e5c..31e09cb 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -92,8 +92,9 @@ export function getCalendarTable(year, month) { list.push(tmp) } - nd = list.length % 7 - nd = nd > 0 ? 7 - nd : 0 + // nd = list.length % 7 + // nd = nd > 0 ? 7 - nd : 0 + nd = 42 - list.length // 统一补够6行 // 修正年月日的数值, 以匹配节假日 if (nd > 0) { @@ -140,7 +141,7 @@ function drawThead(year, month) { function drawTbody(year, month) { var table = getCalendarTable(year, month) var line = 0 - var maxi = 3 * Math.ceil(table.length / 7) + var maxi = 3 * Math.ceil(table.length / 7) // 每个单元格占3行, 所以要 * 3 // i 是 纵坐标, j是横坐标格子 for (let i = 0; i < maxi + 1; i++) {