mirror of
https://shylinux.com/x/volcanos
synced 2025-04-26 17:24:06 +08:00
opt some
This commit is contained in:
parent
8231ca15df
commit
28fcaa1af5
35
lib/lunar.js
35
lib/lunar.js
@ -1,20 +1,15 @@
|
|||||||
var calendar = { /* @1900-2100区间内的公历转农历 */
|
var calendar = { /* @1900-2100区间内的公历转农历 */
|
||||||
solar2lunar: function(date) { /* 传入公历年月日获得详细的公历、农历的信息,参数区间 1900.1.31~2100.12.31 */
|
solar2lunar: function(date) { var y = date.getFullYear(), m = date.getMonth()+1, d = date.getDate()
|
||||||
var y = date.getFullYear(), m = date.getMonth()+1, d = date.getDate()
|
var day = (Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) - Date.UTC(1900,0,31))/86400000
|
||||||
|
for (var year = 1900, days = 0; year < 2101 && day > 0; year++) { days = this.lYearDays(year), day -= days } if (day < 0) { day += days, year-- }
|
||||||
// 农历
|
var isLeap = false, leap = this.leapMonth(year); for (var month = 1; month < 13 && day > 0; month++) {
|
||||||
var offset = (Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) - Date.UTC(1900,0,31))/86400000
|
if (leap > 0 && month == leap+1 && isLeap == false) { month--, isLeap = true, days = this.leapDays(year) } else { days = this.monthDays(year, month) }
|
||||||
for (var i = 1900, temp = 0; i < 2101 && offset > 0; i++) { temp = this.lYearDays(i), offset -= temp } if (offset < 0) { offset += temp, i-- }
|
if (isLeap == true && month == leap+1) { isLeap = false } day -= days
|
||||||
var year = i, isLeap = false, leap = this.leapMonth(i); for (i = 1; i < 13 && offset > 0; i++) {
|
} if (day == 0 && leap > 0 && month == leap+1) { if (isLeap) { isLeap = false } else { isLeap = true, month-- } } if (day < 0) { day += days, month-- } day++
|
||||||
if (leap > 0 && i == leap+1 && isLeap == false) { --i, isLeap = true, temp = this.leapDays(year) } else { temp = this.monthDays(year, i) }
|
|
||||||
if (isLeap == true && i == leap+1) { isLeap = false } offset -= temp
|
|
||||||
} if (offset == 0 && leap > 0 && i == leap+1) { if (isLeap) { isLeap = false } else { isLeap = true, --i } } if (offset < 0) { offset += temp, --i }
|
|
||||||
var month = i, day = offset + 1
|
|
||||||
|
|
||||||
// 节气
|
// 节气
|
||||||
var isTerm = false, term = null, firstTerm = this.getTerm(y, (m*2-1)), secondTerm = this.getTerm(y, (m*2))
|
var term = null, firstTerm = this.getTerm(y, (m*2-1)), secondTerm = this.getTerm(y, (m*2))
|
||||||
if (firstTerm == d) { isTerm = true, term = this.termName[m*2-2] } if (secondTerm == d) { isTerm = true, term = this.termName[m*2-1] }
|
if (d == firstTerm) { term = this.termName[m*2-2] } else if (d == secondTerm) { term = this.termName[m*2-1] }
|
||||||
|
|
||||||
// 干支
|
// 干支
|
||||||
var gzY = this.toGanZhiYear(year)
|
var gzY = this.toGanZhiYear(year)
|
||||||
var gzM = this.toGanZhi((y-1900)*12+m+(d >= firstTerm? 12: 11))
|
var gzM = this.toGanZhi((y-1900)*12+m+(d >= firstTerm? 12: 11))
|
||||||
@ -23,15 +18,13 @@ var calendar = { /* @1900-2100区间内的公历转农历 */
|
|||||||
var nWeek = date.getDay(), cWeek = this.nStr3[nWeek]; if (nWeek == 0) { nWeek = 7 }
|
var nWeek = date.getDay(), cWeek = this.nStr3[nWeek]; if (nWeek == 0) { nWeek = 7 }
|
||||||
function getFestival(list, m, d) { return list[m+"-"+d]? list[m+"-"+d].title: null }
|
function getFestival(list, m, d) { return list[m+"-"+d]? list[m+"-"+d].title: null }
|
||||||
|
|
||||||
var res = {date: y+'-'+m+'-'+d,
|
var res = {date: y+'-'+m+'-'+d, lunarDate: year+'-'+month+'-'+day,
|
||||||
Year: y, Month: m, Day: d,
|
Year: y, Month: m, Day: d, lYear: year, lMonth: month, lDay: day, gzYear: gzY, gzMonth: gzM, gzDay: gzD,
|
||||||
lunarDate: year+'-'+month+'-'+day,
|
|
||||||
lYear: year, lMonth: month, lDay: day,
|
|
||||||
gzYear: gzY, gzMonth: gzM, gzDay: gzD,
|
|
||||||
Animal: this.getAnimal(year), cnMonth: (isLeap?"\u95f0":'')+this.toChinaMonth(month), cnDay: this.toChinaDay(day),
|
Animal: this.getAnimal(year), cnMonth: (isLeap?"\u95f0":'')+this.toChinaMonth(month), cnDay: this.toChinaDay(day),
|
||||||
isLeap: isLeap, isTerm: isTerm, Term: term, Astro: this.toAstro(m, d), nWeek: nWeek, ncWeek: "\u661f\u671f"+cWeek,
|
isLeap: isLeap, Term: term, Astro: this.toAstro(m, d), nWeek: nWeek, ncWeek: "\u661f\u671f"+cWeek,
|
||||||
lunarFestival: getFestival(this.lfestival, month, day), festival: getFestival(this.festival, m, d),
|
lunarFestival: getFestival(this.lfestival, month, day), festival: getFestival(this.festival, m, d),
|
||||||
}; res.autoDay = res.lunarFestival||res.festival||term||(day==1? this.toChinaMonth(month): this.toChinaDay(day))
|
}
|
||||||
|
res.autoDay = res.lunarFestival||res.festival||term||(day==1? this.toChinaMonth(month): this.toChinaDay(day))
|
||||||
res.autoClass = "lunar"+(res.lunarFestival||res.festival? " fest":"")+(res.isTerm? " term": "")
|
res.autoClass = "lunar"+(res.lunarFestival||res.festival? " fest":"")+(res.isTerm? " term": "")
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
@ -44,7 +44,7 @@ Volcanos(chat.ONFIGURE, {date: {
|
|||||||
for (var day = new Date(head); day < one; day.setDate(day.getDate()+1)) { add(day, mdb.PREV) }
|
for (var day = new Date(head); day < one; day.setDate(day.getDate()+1)) { add(day, mdb.PREV) }
|
||||||
for (var day = new Date(one); day < end; day.setDate(day.getDate()+1)) { add(day, mdb.MAIN) }
|
for (var day = new Date(one); day < end; day.setDate(day.getDate()+1)) { add(day, mdb.MAIN) }
|
||||||
for (var day = new Date(end); end.getDay() != 0 && day < tail; day.setDate(day.getDate()+1)) { add(day, mdb.NEXT) }
|
for (var day = new Date(end); end.getDay() != 0 && day < tail; day.setDate(day.getDate()+1)) { add(day, mdb.NEXT) }
|
||||||
var l = lunar(now); can.page.Appends(can, can._status, [{view: "today", inner: [l.gzYear, l.Animal+"年", l.Astro].join(ice.SP)}])
|
var l = lunar(now); can.page.Appends(can, can._status, [{view: "today", inner: [l.gzYear, l.Animal+"年", l.cnMonth, l.cnDay, l.lunarFestival||l.festival||l.Term, l.Astro].join(ice.SP)}])
|
||||||
return now
|
return now
|
||||||
}
|
}
|
||||||
can.require(["/lib/lunar.js"], function() { lunar = function(day) { return calendar.solar2lunar(day) }
|
can.require(["/lib/lunar.js"], function() { lunar = function(day) { return calendar.solar2lunar(day) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user