getFiveElementClass function
FiveElementsFormat
getFiveElementClass(
- HeavenlyStemName heavenlyStemName,
- EarthlyBranchName earthlyBranchName
定五行局法(以命宫天干地支而定)
纳音五行计算取数巧记口诀:
- 甲乙丙丁一到五,子丑午未一来数,
- 寅卯申酉二上走,辰巳戌亥三为足。
- 干支相加多减五,五行木金水火土。
注解:
1、五行取数:木1 金2 水3 火4 土5
天干取数:
- 甲乙 ——> 1
- 丙丁 ——> 2
- 戊己 ——> 3
- 庚辛 ——> 4
- 壬癸 ——> 5
地支取数:
- 子午丑未 ——> 1
- 寅申卯酉 ——> 2
- 辰戌巳亥 ——> 3
2、计算方法:
干支数相加,超过5者减去5,以差论之。
- 若差为1则五行属木
- 若差为2则五行属金
- 若差为3则五行属水
- 若差为4则五行属火
- 若差为5则五行属土
3、举例:
- 丙子:丙2 子1=3 ——> 水 ——> 水二局
- 辛未:辛4 未1=5 ——> 土 ——> 土五局
- 庚申:庚4 申2=6 ——> 6-5=1 ——> 木 ——> 木三局
@param heavenlyStemName 天干 @param earthlyBranchName 地支 @returns 水二局 | 木三局 | 金四局 | 土五局 | 火六局
Implementation
FiveElementsFormat getFiveElementClass(
HeavenlyStemName heavenlyStemName,
EarthlyBranchName earthlyBranchName,
) {
const fiveElementsTable = [
'wood3rd',
'metal4th',
'water2nd',
'fire6th',
'earth5th',
];
final heavenlyStemNumber =
(heavenlyStems.indexOf(heavenlyStemName.key) / 2).floor() + 1;
final earthlyBranchNumber =
(fixIndex(earthlyBranches.indexOf(earthlyBranchName.key), max: 6) / 2)
.floor() +
1;
var index = heavenlyStemNumber + earthlyBranchNumber;
while (index > 5) {
index -= 5;
}
return FiveElementsFormat.fiveElementFrom(fiveElementsTable[index - 1]);
}