MCPcopy Create free account
hub / github.com/6tail/lunar-java / computeYear

Method computeYear

src/main/java/com/nlf/calendar/Lunar.java:237–299  ·  view source on GitHub ↗

计算干支纪年

()

Source from the content-addressed store, hash-verified

235 * 计算干支纪年
236 */
237 private void computeYear() {
238 //以正月初一开始
239 int offset = year - 4;
240 yearGanIndex = offset % 10;
241 yearZhiIndex = offset % 12;
242
243 if (yearGanIndex < 0) {
244 yearGanIndex += 10;
245 }
246
247 if (yearZhiIndex < 0) {
248 yearZhiIndex += 12;
249 }
250
251 //以立春作为新一年的开始的干支纪年
252 int g = yearGanIndex;
253 int z = yearZhiIndex;
254
255 //精确的干支纪年,以立春交接时刻为准
256 int gExact = yearGanIndex;
257 int zExact = yearZhiIndex;
258
259 int solarYear = solar.getYear();
260 String solarYmd = solar.toYmd();
261 String solarYmdHms = solar.toYmdHms();
262
263 //获取立春的阳历时刻
264 Solar liChun = jieQi.get("立春");
265 if (liChun.getYear() != solarYear) {
266 liChun = jieQi.get("LI_CHUN");
267 }
268 String liChunYmd = liChun.toYmd();
269 String liChunYmdHms = liChun.toYmdHms();
270
271 //阳历和阴历年份相同代表正月初一及以后
272 if (year == solarYear) {
273 //立春日期判断
274 if (solarYmd.compareTo(liChunYmd) < 0) {
275 g--;
276 z--;
277 }
278 //立春交接时刻判断
279 if (solarYmdHms.compareTo(liChunYmdHms) < 0) {
280 gExact--;
281 zExact--;
282 }
283 } else if (year < solarYear) {
284 if (solarYmd.compareTo(liChunYmd) >= 0) {
285 g++;
286 z++;
287 }
288 if (solarYmdHms.compareTo(liChunYmdHms) >= 0) {
289 gExact++;
290 zExact++;
291 }
292 }
293
294 yearGanIndexByLiChun = (g < 0 ? g + 10 : g) % 10;

Callers 1

computeMethod · 0.95

Calls 4

toYmdMethod · 0.95
toYmdHmsMethod · 0.95
getYearMethod · 0.95
getYearMethod · 0.45

Tested by

no test coverage detected