@@ -15,40 +15,64 @@ public class Yun {
1515 * 性别(1男,0女)
1616 */
1717 private int gender ;
18+
1819 /**
1920 * 起运年数
2021 */
2122 private int startYear ;
23+
2224 /**
2325 * 起运月数
2426 */
2527 private int startMonth ;
28+
2629 /**
2730 * 起运天数
2831 */
2932 private int startDay ;
33+
34+ /**
35+ * 起运小时数
36+ */
37+ private int startHour ;
38+
3039 /**
3140 * 是否顺推
3241 */
3342 private boolean forward ;
43+
3444 private Lunar lunar ;
3545
46+ /**
47+ * 使用默认流派1初始化运
48+ * @param eightChar 八字
49+ * @param gender 性别,1男,0女
50+ */
3651 public Yun (EightChar eightChar , int gender ) {
52+ this (eightChar , gender , 1 );
53+ }
54+
55+ /**
56+ * 初始化运
57+ * @param eightChar 八字
58+ * @param gender 性别,1男,0女
59+ * @param sect 流派,1按天数和时辰数计算,3天1年,1天4个月,1时辰10天;2按分钟数计算
60+ */
61+ public Yun (EightChar eightChar , int gender , int sect ) {
3762 this .lunar = eightChar .getLunar ();
3863 this .gender = gender ;
3964 // 阳
4065 boolean yang = 0 == lunar .getYearGanIndexExact () % 2 ;
4166 // 男
4267 boolean man = 1 == gender ;
4368 forward = (yang && man ) || (!yang && !man );
44- computeStart ();
69+ computeStart (sect );
4570 }
4671
4772 /**
4873 * 起运计算
4974 */
50- @ SuppressWarnings ("MagicConstant" )
51- private void computeStart () {
75+ private void computeStart (int sect ) {
5276 // 上节
5377 JieQi prev = lunar .getPrevJie ();
5478 // 下节
@@ -58,24 +82,46 @@ private void computeStart() {
5882 // 阳男阴女顺推,阴男阳女逆推
5983 Solar start = forward ? current : prev .getSolar ();
6084 Solar end = forward ? next .getSolar () : current ;
61- int endTimeZhiIndex = (end .getHour () == 23 ) ? 11 : LunarUtil .getTimeZhiIndex (end .toYmdHms ().substring (11 , 16 ));
62- int startTimeZhiIndex = (start .getHour () == 23 ) ? 11 : LunarUtil .getTimeZhiIndex (start .toYmdHms ().substring (11 , 16 ));
63- // 时辰差
64- int hourDiff = endTimeZhiIndex - startTimeZhiIndex ;
65- // 天数差
66- int dayDiff = ExactDate .getDaysBetween (start .getYear (), start .getMonth (), start .getDay (), end .getYear (), end .getMonth (), end .getDay ());
67- if (hourDiff < 0 ) {
68- hourDiff += 12 ;
69- dayDiff --;
85+
86+ int year ;
87+ int month ;
88+ int day ;
89+ int hour = 0 ;
90+
91+ if (2 == sect ) {
92+ long minutes = (end .getCalendar ().getTimeInMillis () - start .getCalendar ().getTimeInMillis ()) / 60000 ;
93+ long y = minutes / 4320 ;
94+ minutes -= y * 4320 ;
95+ long m = minutes / 360 ;
96+ minutes -= m * 360 ;
97+ long d = minutes / 12 ;
98+ minutes -= d * 12 ;
99+ long h = minutes * 2 ;
100+ year = (int )y ;
101+ month = (int )m ;
102+ day = (int )d ;
103+ hour = (int )h ;
104+ } else {
105+ int endTimeZhiIndex = (end .getHour () == 23 ) ? 11 : LunarUtil .getTimeZhiIndex (end .toYmdHms ().substring (11 , 16 ));
106+ int startTimeZhiIndex = (start .getHour () == 23 ) ? 11 : LunarUtil .getTimeZhiIndex (start .toYmdHms ().substring (11 , 16 ));
107+ // 时辰差
108+ int hourDiff = endTimeZhiIndex - startTimeZhiIndex ;
109+ // 天数差
110+ int dayDiff = ExactDate .getDaysBetween (start .getYear (), start .getMonth (), start .getDay (), end .getYear (), end .getMonth (), end .getDay ());
111+ if (hourDiff < 0 ) {
112+ hourDiff += 12 ;
113+ dayDiff --;
114+ }
115+ int monthDiff = hourDiff * 10 / 30 ;
116+ month = dayDiff * 4 + monthDiff ;
117+ day = hourDiff * 10 - monthDiff * 30 ;
118+ year = month / 12 ;
119+ month = month - year * 12 ;
70120 }
71- int monthDiff = hourDiff * 10 / 30 ;
72- int month = dayDiff * 4 + monthDiff ;
73- int day = hourDiff * 10 - monthDiff * 30 ;
74- int year = month / 12 ;
75- month = month - year * 12 ;
76121 this .startYear = year ;
77122 this .startMonth = month ;
78123 this .startDay = day ;
124+ this .startHour = hour ;
79125 }
80126
81127 /**
@@ -114,6 +160,15 @@ public int getStartDay() {
114160 return startDay ;
115161 }
116162
163+ /**
164+ * 获取起运小时数
165+ *
166+ * @return 起运小时数
167+ */
168+ public int getStartHour () {
169+ return startHour ;
170+ }
171+
117172 /**
118173 * 是否顺推
119174 *
@@ -132,13 +187,13 @@ public Lunar getLunar() {
132187 *
133188 * @return 阳历日期
134189 */
135- @ SuppressWarnings ("MagicConstant" )
136190 public Solar getStartSolar () {
137191 Solar birth = lunar .getSolar ();
138- Calendar c = ExactDate .fromYmd (birth .getYear (), birth .getMonth (), birth .getDay ());
192+ Calendar c = ExactDate .fromYmdHms (birth .getYear (), birth .getMonth (), birth .getDay (), birth . getHour (), birth . getMinute (), birth . getSecond ());
139193 c .add (Calendar .YEAR , startYear );
140194 c .add (Calendar .MONTH , startMonth );
141195 c .add (Calendar .DATE , startDay );
196+ c .add (Calendar .HOUR , startHour );
142197 return Solar .fromCalendar (c );
143198 }
144199
0 commit comments