parent
6ac40d81c3
commit
7d2d5841f0
BIN
img/demo.png
BIN
img/demo.png
Binary file not shown.
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 51 KiB |
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "bash-calendar",
|
"name": "bash-calendar",
|
||||||
"description": "终端版万年历",
|
"description": "终端版万年历",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"author": "yutent <yutent.io@gmail.com>",
|
"author": "yutent <yutent.io@gmail.com>",
|
||||||
"bin": {
|
"bin": {
|
||||||
"calendar": "index.js",
|
"calendar": "index.js",
|
||||||
|
|
|
@ -67,7 +67,7 @@ export function getCalendarTable(year, month) {
|
||||||
tmp.weekend = week === 0 || week === 6
|
tmp.weekend = week === 0 || week === 6
|
||||||
tmp.picked = !!isPicked({ year, month, day: i }, today)
|
tmp.picked = !!isPicked({ year, month, day: i }, today)
|
||||||
tmp.lunar = lunar.short
|
tmp.lunar = lunar.short
|
||||||
tmp.highlight = !!lunar.festival
|
tmp.highlight = !!lunar.festival || !!lunar.solarTerms
|
||||||
} else {
|
} else {
|
||||||
// 从上个月中补齐第1周
|
// 从上个月中补齐第1周
|
||||||
tmp.grey = 1
|
tmp.grey = 1
|
||||||
|
@ -137,7 +137,7 @@ function drawTbody(year, month) {
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
if (tmp.picked) {
|
if (tmp.picked) {
|
||||||
tr += ' ' + chalk.bgRed.whiteBright.bold(' ' + tmp.day + ' ') + ' ' + VLINE
|
tr += ' ' + chalk.bgBlue.whiteBright.bold(' ' + tmp.day + ' ') + ' ' + VLINE
|
||||||
} else {
|
} else {
|
||||||
// 有grey字段的, 优先置灰, 这种为 非本月份的日期
|
// 有grey字段的, 优先置灰, 这种为 非本月份的日期
|
||||||
if (tmp.grey) {
|
if (tmp.grey) {
|
||||||
|
@ -161,7 +161,7 @@ function drawTbody(year, month) {
|
||||||
if (tmp.picked) {
|
if (tmp.picked) {
|
||||||
tr +=
|
tr +=
|
||||||
' ' +
|
' ' +
|
||||||
chalk.bgRed.white.bold(' '.repeat(pad) + tmp.lunar + ' '.repeat(pad)) +
|
chalk.bgBlue.white.bold(' '.repeat(pad) + tmp.lunar + ' '.repeat(pad)) +
|
||||||
' ' +
|
' ' +
|
||||||
VLINE
|
VLINE
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -236,7 +236,7 @@ export const EARTHLY_BRANCHES = [
|
||||||
'亥'
|
'亥'
|
||||||
]
|
]
|
||||||
|
|
||||||
// 24节气表和C值
|
// 24节气表
|
||||||
export const SOLAR_TERMS = [
|
export const SOLAR_TERMS = [
|
||||||
'小寒',
|
'小寒',
|
||||||
'大寒',
|
'大寒',
|
||||||
|
@ -264,6 +264,210 @@ export const SOLAR_TERMS = [
|
||||||
'冬至'
|
'冬至'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const SOLAR_TERMS_YEARS = [
|
||||||
|
'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'
|
||||||
|
]
|
||||||
|
|
||||||
// 农历节日(仅为常规节日, 地方节日、教派节日未收录)
|
// 农历节日(仅为常规节日, 地方节日、教派节日未收录)
|
||||||
export const FESTIVALS = {
|
export const FESTIVALS = {
|
||||||
'1.1': '春节',
|
'1.1': '春节',
|
||||||
|
|
|
@ -12,7 +12,9 @@ import {
|
||||||
EARTHLY_BRANCHES,
|
EARTHLY_BRANCHES,
|
||||||
ZODIAC,
|
ZODIAC,
|
||||||
FESTIVALS,
|
FESTIVALS,
|
||||||
SOLAR_FESTIVALS
|
SOLAR_FESTIVALS,
|
||||||
|
SOLAR_TERMS,
|
||||||
|
SOLAR_TERMS_YEARS
|
||||||
} from './config.js'
|
} from './config.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,7 +26,8 @@ export function solar2lunar(year = 1901, month = 0, day = 1) {
|
||||||
var timestamp = Date.UTC(year, month, day) // 传入日期的时间戳
|
var timestamp = Date.UTC(year, month, day) // 传入日期的时间戳
|
||||||
var offset = (timestamp - baseDate) / (24 * 60 * 60 * 1000) + 1 // 计算与的相差天数, 有1天的修正
|
var offset = (timestamp - baseDate) / (24 * 60 * 60 * 1000) + 1 // 计算与的相差天数, 有1天的修正
|
||||||
var months, leap
|
var months, leap
|
||||||
var result = { short: '' }
|
var result = { short: '', solarTerms: '', festival: '', lunarFestival: '' }
|
||||||
|
var solarTermsYear = SOLAR_TERMS_YEARS[year - 1900]
|
||||||
|
|
||||||
if (year < 1901 || year > 2100) {
|
if (year < 1901 || year > 2100) {
|
||||||
return result
|
return result
|
||||||
|
@ -63,16 +66,28 @@ export function solar2lunar(year = 1901, month = 0, day = 1) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 二十四节气
|
||||||
|
if (solarTermsYear) {
|
||||||
|
let tmp = solarTermsYear.slice(month * 4, (month + 1) * 4)
|
||||||
|
if (+tmp.slice(0, 2) === day) {
|
||||||
|
result.solarTerms = SOLAR_TERMS[month * 2]
|
||||||
|
} else if (+tmp.slice(2) === day) {
|
||||||
|
result.solarTerms = SOLAR_TERMS[month * 2 + 1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 公历节日
|
// 公历节日
|
||||||
result.festival = SOLAR_FESTIVALS[`${month + 1}.${day}`]
|
result.festival = SOLAR_FESTIVALS[`${month + 1}.${day}`] || ''
|
||||||
|
|
||||||
// 非闰月才有农历节日
|
// 非闰月才有农历节日
|
||||||
if (!result.leap) {
|
if (!result.leap) {
|
||||||
// 修正没有年三十的除夕
|
// 修正没有年三十的除夕
|
||||||
if (result.month === 11 && result.day === months.pop()) {
|
if (result.month === 11 && result.day === months.pop()) {
|
||||||
result.festival = FESTIVALS['12.30']
|
result.festival = FESTIVALS['12.30']
|
||||||
|
result.lunarFestival = FESTIVALS['12.30']
|
||||||
} else {
|
} else {
|
||||||
result.festival = FESTIVALS[`${result.month + 1}.${result.day}`] || result.festival
|
result.festival = FESTIVALS[`${result.month + 1}.${result.day}`] || result.festival
|
||||||
|
result.lunarFestival = FESTIVALS[`${result.month + 1}.${result.day}`] || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,9 +105,12 @@ export function solar2lunar(year = 1901, month = 0, day = 1) {
|
||||||
} else if (result.day === 30) {
|
} else if (result.day === 30) {
|
||||||
result.dayCN = LUNAR_DAY[3] + LUNAR_DAY[10]
|
result.dayCN = LUNAR_DAY[3] + LUNAR_DAY[10]
|
||||||
}
|
}
|
||||||
|
// console.log(result)
|
||||||
|
|
||||||
result.short = result.festival
|
result.short = result.festival
|
||||||
? result.festival
|
? result.festival
|
||||||
|
: result.solarTerms
|
||||||
|
? result.solarTerms
|
||||||
: result.day === 1
|
: result.day === 1
|
||||||
? result.monthCN
|
? result.monthCN
|
||||||
: result.dayCN
|
: result.dayCN
|
||||||
|
|
Loading…
Reference in New Issue