Browse Source

fix festival bug

Looly 5 years ago
parent
commit
981bc843e1

+ 3 - 1
CHANGELOG.md

@@ -3,12 +3,14 @@
 
 -------------------------------------------------------------------------------------------------------------
 
-# 5.4.2 (2020-08-29)
+# 5.4.2 (2020-08-31)
 
 ### 新特性
 * 【core  】     lock放在try外边(pr#1050@Github)
+* 【core  】     MailUtil增加错误信息(issue#I1TAKJ@Gitee)
 
 ### Bug修复#
+* 【core  】     重新整理农历节假日,解决一个pr过来的玩笑导致的问题
 
 -------------------------------------------------------------------------------------------------------------
 

+ 71 - 30
hutool-core/src/main/java/cn/hutool/core/date/chinese/LunarFestival.java

@@ -1,8 +1,8 @@
 package cn.hutool.core.date.chinese;
 
-import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.lang.Pair;
+import cn.hutool.core.map.TableMap;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -12,16 +12,75 @@ import java.util.List;
  * @since 5.4.1
  */
 public class LunarFestival {
+
 	//农历节日  *表示放假日
-	private static final String[] lFtv = new String[]{
-			"0101 春节", "0102 大年初二", "0103 大年初三", "0104 大年初四",
-			"0105 大年初五", "0106 大年初六", "0107 大年初七", "0105 路神生日",
-			"0115 元宵节", "0202 龙抬头", "0219 观世音圣诞", "0404 寒食节",
-			"0408 佛诞节 ", "0505 端午节", "0606 天贶节 姑姑节", "0624 彝族火把节",
-			"0707 七夕情人节", "0714 鬼节(南方)", "0715 盂兰节", "0730 地藏节",
-			"0815 中秋节", "0909 重阳节", "1001 祭祖节", "1117 阿弥陀佛圣诞",
-			"1208 腊八节 释迦如来成道日", "1223 过小年", "1229 腊月二十九", "1230 除夕"
-	};
+	// 来自:https://baike.baidu.com/item/%E4%B8%AD%E5%9B%BD%E4%BC%A0%E7%BB%9F%E8%8A%82%E6%97%A5/396100
+	private static final TableMap<Pair<Integer, Integer>, String> lFtv = new TableMap<>(16);
+	static{
+		lFtv.put(new Pair<>(1, 1), "春节");
+		lFtv.put(new Pair<>(1, 2), "犬日");
+		lFtv.put(new Pair<>(1, 3), "猪日");
+		lFtv.put(new Pair<>(1, 4), "羊日");
+		lFtv.put(new Pair<>(1, 5), "牛日 破五日");
+		lFtv.put(new Pair<>(1, 6), "马日,送穷日");
+		lFtv.put(new Pair<>(1, 7), "人日 人胜节");
+		lFtv.put(new Pair<>(1, 8), "谷日 八仙日");
+		lFtv.put(new Pair<>(1, 9), "天日 九皇会");
+		lFtv.put(new Pair<>(1, 10), "地日 石头生日");
+		lFtv.put(new Pair<>(1, 12), "火日 老鼠娶媳妇日");
+		lFtv.put(new Pair<>(1, 13), "上(试)灯日 关公升天日");
+		lFtv.put(new Pair<>(1, 15), "元宵节");
+		lFtv.put(new Pair<>(1, 18), "落灯日");
+
+		// 二月
+		lFtv.put(new Pair<>(2, 1), "中和节 太阳生日");
+		lFtv.put(new Pair<>(2, 2), "龙抬头");
+		lFtv.put(new Pair<>(2, 12), "花朝节");
+		lFtv.put(new Pair<>(2, 19), "观世音圣诞");
+
+		// 三月
+		lFtv.put(new Pair<>(3, 3), "上巳节");
+
+		// 四月
+		lFtv.put(new Pair<>(4, 1), "祭雹神");
+		lFtv.put(new Pair<>(4, 4), "文殊菩萨诞辰");
+		lFtv.put(new Pair<>(4, 8), "佛诞节");
+
+		// 五月
+		lFtv.put(new Pair<>(5, 5), "端午节");
+
+		// 六月
+		lFtv.put(new Pair<>(6, 6), "晒衣节 姑姑节");
+		lFtv.put(new Pair<>(6, 6), "天贶节");
+		lFtv.put(new Pair<>(6, 24), "彝族火把节");
+
+		// 七月
+		lFtv.put(new Pair<>(7, 7), "七夕");
+		lFtv.put(new Pair<>(7, 14), "鬼节(南方)");
+		lFtv.put(new Pair<>(7, 15), "中元节");
+		lFtv.put(new Pair<>(7, 15), "盂兰盆节");
+		lFtv.put(new Pair<>(7, 30), "地藏节");
+
+		// 八月
+		lFtv.put(new Pair<>(8, 15), "中秋节");
+
+		// 九月
+		lFtv.put(new Pair<>(9, 9), "重阳节");
+
+		// 十月
+		lFtv.put(new Pair<>(10, 1), "祭祖节");
+		lFtv.put(new Pair<>(10, 15), "下元节");
+
+		// 十一月
+		lFtv.put(new Pair<>(11, 17), "阿弥陀佛圣诞");
+
+		// 腊月
+		lFtv.put(new Pair<>(12, 8), "腊八节");
+		lFtv.put(new Pair<>(12, 16), "尾牙");
+		lFtv.put(new Pair<>(12, 23), "小年");
+		lFtv.put(new Pair<>(12, 29), "除夕");
+		lFtv.put(new Pair<>(12, 30), "除夕");
+	}
 
 	/**
 	 * 获得节日列表
@@ -31,24 +90,6 @@ public class LunarFestival {
 	 * @return 获得农历节日
 	 */
 	public static List<String> getFestivals(int month, int day) {
-		final StringBuilder currentChineseDate = new StringBuilder();
-		if (month < 10) {
-			currentChineseDate.append('0');
-		}
-		currentChineseDate.append(month);
-
-		if (day < 10) {
-			currentChineseDate.append('0');
-		}
-		currentChineseDate.append(day);
-
-		final List<String> result = new ArrayList<>();
-		for (String fv : lFtv) {
-			final List<String> split = StrUtil.split(fv, ' ');
-			if (split.get(0).contentEquals(currentChineseDate)) {
-				result.add(split.get(1));
-			}
-		}
-		return result;
+		return lFtv.getValues(new Pair<>(month, day));
 	}
 }

+ 8 - 0
hutool-extra/src/main/java/cn/hutool/extra/mail/Mail.java

@@ -11,9 +11,11 @@ import javax.activation.DataHandler;
 import javax.activation.DataSource;
 import javax.activation.FileDataSource;
 import javax.activation.FileTypeMap;
+import javax.mail.Address;
 import javax.mail.Authenticator;
 import javax.mail.MessagingException;
 import javax.mail.Multipart;
+import javax.mail.SendFailedException;
 import javax.mail.Session;
 import javax.mail.Transport;
 import javax.mail.internet.MimeBodyPart;
@@ -355,6 +357,12 @@ public class Mail {
 		try {
 			return doSend();
 		} catch (MessagingException e) {
+			if(e instanceof SendFailedException){
+				// 当地址无效时,显示更加详细的无效地址信息
+				final Address[] invalidAddresses = ((SendFailedException) e).getInvalidAddresses();
+				final String msg = StrUtil.format("Invalid Addresses: {}", ArrayUtil.toString(invalidAddresses));
+				throw new MailException(msg, e);
+			}
 			throw new MailException(e);
 		}
 	}