@z-yue/calendar
Version:
根据当前阳(公)历日期获取阴(农)历日期,节日
3 lines (2 loc) • 2.57 kB
JavaScript
"use strict";const t=["","正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","冬月","腊月"],s=["","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"];class i{constructor(t=new Date){this.LOCALES="ja-JP-u-ca-chinese",this.match=(t,s)=>this.month===t&&this.date===s,this.isNewYear=()=>this.match(1,1)||this.match(1,2)||this.match(1,3)||this.match(1,4)||this.match(1,5)||this.match(1,6)||this.match(1,7),this.isLantern=()=>this.match(1,15),this.isDoubleSeventh=()=>this.match(7,7),this.isMidAutumn=()=>this.match(8,15),this.isDoubleNinth=()=>this.match(9,9),this.now=t.toLocaleString(this.LOCALES),this.publicDate=t}get year(){return this.now.slice(0,this.now.search(/\d+月/))}get month(){return parseInt(this.now.slice(this.now.search(/\d+月/),this.now.search(/月/)))}get date(){return parseInt(this.now.slice(this.now.search(/\d+日/),this.now.search(/日/)))}get lunarMonth(){return t[this.month]||""}get lunarDate(){return s[this.date]||""}get isBigMonth(){const t=30-this.date,s=new Date(this.publicDate);s.setDate(s.getDate()+t);const i=s.toLocaleString("ja-JP-u-ca-chinese");return parseInt(i.slice(i.search(/\d+月/),i.search(/月/)))===this.month}get isSmallMonth(){return!this.isBigMonth}get full(){return`${this.year}${this.lunarMonth}${this.lunarDate}`}get festival(){return this.isNewYear()?"新年":this.isLantern()?"元宵节":this.isDoubleSeventh()?"七夕节":this.isMidAutumn()?"中秋节":this.isDoubleNinth()?"重阳节":""}}module.exports=class{constructor(t=new Date){this.match=(t,s)=>this.month===t&&this.date===s,this.isTombSweeping=()=>this.match(4,4),this.isValentineDay=()=>this.match(2,14),this.isAprilFoolDay=()=>this.match(4,1),this.isChristmas=()=>this.match(12,25),this.isHalloween=()=>this.match(10,31),this.isNewYear=()=>this.match(1,1),this.now=t,this.lunar=new i(t)}get year(){return this.now.getFullYear()}get month(){return this.now.getMonth()+1}get date(){return this.now.getDate()}get day(){return this.now.getDay()}get festival(){return this.isTombSweeping()?"清明节":this.isValentineDay()?"情人节":this.isAprilFoolDay()?"愚人节":this.isChristmas()?"圣诞节":this.isHalloween()?"万圣节":this.isNewYear()?"元旦节":""}get fullFestival(){return[this.festival,this.lunar.festival].filter((t=>""!==t)).join(" ")}};
//# sourceMappingURL=index.min.js.map