Skip to content

Commit

Permalink
1.新增 DateUtils#getZodiac、getConstellation、getConstellationDate
Browse files Browse the repository at this point in the history
Former-commit-id: 0e07b35
Former-commit-id: 5dd9f5a
  • Loading branch information
Ttt committed Sep 22, 2020
1 parent 692544e commit cdfde37
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/DevApp/src/main/java/dev/utils/common/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1099,4 +1099,54 @@ public static long getEndTimeDiff(final long startTime, final String endTime, fi
}
return -1;
}

// ==============
// = 生肖、星座 =
// ==============

// 生肖数组
private static final String[] ZODIAC = {"猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊"};
// 星座截止天数
private static final int[] CONSTELLATION_DAY = {20, 19, 21, 21, 21, 22, 23, 23, 23, 24, 23, 22};
// 星座对应日期
private static final String[] CONSTELLATION_DATE = {
"01.20-02.18", "02.19-03.20", "03.21-04.19", "04.20-05.20", "05.21-06.21", "06.22-07.22",
"07.23-08.22", "08.23-09.22", "09.23-10.23", "10.24-11.22", "11.23-12.21", "12.22-01.19"
};
// 星座数组
private static final String[] CONSTELLATION = {
"水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座",
"狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座"
};

/**
* 获取生肖
* @param year 年份
* @return 生肖
*/
public static String getZodiac(final int year) {
return ZODIAC[Math.abs(year) % 12];
}

/**
* 获取星座
* @param month 月份
* @param day 天数
* @return 星座
*/
public static String getConstellation(final int month, final int day) {
if (month > 12 || month < 1) return null;
return CONSTELLATION[day >= CONSTELLATION_DAY[month - 1] ? month - 1 : (month + 10) % 12];
}

/**
* 获取星座日期
* @param month 月份
* @param day 天数
* @return 星座日期
*/
public static String getConstellationDate(final int month, final int day) {
if (month > 12 || month < 1) return null;
return CONSTELLATION_DATE[day >= CONSTELLATION_DAY[month - 1] ? month - 1 : (month + 10) % 12];
}
}

0 comments on commit cdfde37

Please sign in to comment.