1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* Copyright (C) 2014 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: jouyouyun <jouyouwen717@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package lunar
import (
"math"
"github.com/linuxdeepin/go-lib/calendar/util"
)
var SolarTermNames = []string{
"春分",
"清明",
"谷雨",
"立夏",
"小满",
"芒种",
"夏至",
"小暑",
"大暑",
"立秋",
"处暑",
"白露",
"秋分",
"寒露",
"霜降",
"立冬",
"小雪",
"大雪",
"冬至",
"小寒",
"大寒",
"立春",
"雨水",
"惊蛰",
}
const (
ChunFen int = iota
QingMing
GuYu
LiXia
XiaoMan
MangZhong
XiaZhi
XiaoShu
DaShu
LiQiu
ChuShu
BaiLu
QiuFen
HanLu
ShuangJiang
LiDong
XiaoXue
DaXue
DongZhi
XiaoHan
DaHan
LiChun
YuShui
JingZhe
)
// GetSolarTermName 获取二十四节气名
func GetSolarTermName(order int) string {
if 0 <= order && order <= 23 {
return SolarTermNames[order]
}
return ""
}
// GetSolarTermJD 使用牛顿迭代法计算24节气的时间
// f(x) = Vsop87dEarthUtil.getEarthEclipticLongitudeForSun(x) - angle = 0
// year 年
// order 节气序号
// 返回 节气的儒略日力学时间 TD
func GetSolarTermJD(year, order int) float64 {
const RADIANS_PER_TERM = math.Pi / 12.0
angle := float64(order) * RADIANS_PER_TERM
month := ((order+1)/2+2)%12 + 1
// 春分 order 0
// 3 月 20 号
var day int = 6
if order%2 == 0 {
day = 20
}
jd0 := util.ToJulianDateHMS(year, month, day, 12, 0, 0.0)
jd := NewtonIteration(func(x float64) float64 {
return ModPi(GetEarthEclipticLongitudeForSun(x) - angle)
}, jd0)
return jd
}
|