lunisolar
Version:
专业农历库,支持公历阴历互转,支持各类黄历数据查询,如八字四柱、阴历、神煞宜忌、时辰吉凶、建除十二神、胎神占方、五行纳音等。支持自定义插件。
41 lines (37 loc) • 816 B
text/typescript
/*
----
長生十二神
----
*/
import { getBranchValue, getStemValue } from '../../../utils'
export const life12GodNames = [
'長生',
'沐浴',
'冠帶',
'臨官',
'帝旺',
'衰',
'病',
'死',
'墓',
'絕',
'胎',
'養'
]
/**
* @param lsr The instance of Lunisolar
* @returns [長生12神索引, 名稱key]
*/
export const getLife12God = function (
lsr: lunisolar.Lunisolar,
ymdh: YMDH = 'day'
): [number, string] {
const stemValue = getStemValue(lsr, ymdh)
const branchValue = getBranchValue(lsr, ymdh)
const offsetList = [1, 6, 10, 9, 10, 9, 7, 0, 4, 3]
const isRev = stemValue % 2 === 1
const offset = offsetList[stemValue]
const godIdx = (12 + (isRev ? 12 - branchValue : branchValue) + offset) % 12
const key = life12GodNames[godIdx]
return [godIdx, key]
}