getConstellationWith method
根据月份和日期获取星座
例子: 19960515, 则getConstellationWith(5,15);
month
月份
day
日期
Implementation
String getConstellationWith(int month, int day) {
const String capricorn = '摩羯座'; //Capricorn 摩羯座(12月22日~1月20日)
const String aquarius = '水瓶座'; //Aquarius 水瓶座(1月21日~2月19日)
const String pisces = '双鱼座'; //Pisces 双鱼座(2月20日~3月20日)
const String aries = '白羊座'; //3月21日~4月20日
const String taurus = '金牛座'; //4月21~5月21日
const String gemini = '双子座'; //5月22日~6月21日
const String cancer = '巨蟹座'; //Cancer 巨蟹座(6月22日~7月22日)
const String leo = '狮子座'; //Leo 狮子座(7月23日~8月23日)
const String virgo = '处女座'; //Virgo 处女座(8月24日~9月23日)
const String libra = '天秤座'; //Libra 天秤座(9月24日~10月23日)
const String scorpio = '天蝎座'; //Scorpio 天蝎座(10月24日~11月22日)
const String sagittarius = '射手座'; //Sagittarius 射手座(11月23日~12月21日)
String constellation = '';
///去掉月份的0
if (month.toString().startsWith('0')) {
month = int.parse(month.toString().replaceAll('0', ''));
}
switch (month) {
case DateTime.january:
constellation = day < 21 ? capricorn : aquarius;
break;
case DateTime.february:
constellation = day < 20 ? aquarius : pisces;
break;
case DateTime.march:
constellation = day < 21 ? pisces : aries;
break;
case DateTime.april:
constellation = day < 21 ? aries : taurus;
break;
case DateTime.may:
constellation = day < 22 ? taurus : gemini;
break;
case DateTime.june:
constellation = day < 22 ? gemini : cancer;
break;
case DateTime.july:
constellation = day < 23 ? cancer : leo;
break;
case DateTime.august:
constellation = day < 24 ? leo : virgo;
break;
case DateTime.september:
constellation = day < 24 ? virgo : libra;
break;
case DateTime.october:
constellation = day < 24 ? libra : scorpio;
break;
case DateTime.november:
constellation = day < 23 ? scorpio : sagittarius;
break;
case DateTime.december:
constellation = day < 22 ? sagittarius : capricorn;
break;
}
return constellation;
}