From 85dce973eb29eb2372c76d5b95b30354da9c41c8 Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Tue, 22 Feb 2022 23:08:51 +0800
Subject: [PATCH] fead:新增收银员字段

---
 zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java b/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
index 4fdaef7..01df901 100644
--- a/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
+++ b/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
@@ -720,10 +720,45 @@
                 targetDate = calendar.getTime();
                 break;
             default:
-                targetDate = new Date();
+                targetDate = stringToDate("2099-12-31", DATE_FORMAT_DD);
 
         }
 
 		return targetDate;
 	}
+
+	public static String getAgeForBirthDay(Date birthDay) {
+		Calendar cal = Calendar.getInstance();
+		if (birthDay == null) {
+		    return "-";
+        }
+		// 出生日期晚于当前时间,无法计算
+		if (cal.before(birthDay)) {
+			return "-";
+		}
+        // 当前年份
+		int yearNow = cal.get(Calendar.YEAR);
+        // 当前月份
+		int monthNow = cal.get(Calendar.MONTH);
+        // 当前日期
+		int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
+		cal.setTime(birthDay);
+		int yearBirth = cal.get(Calendar.YEAR);
+		int monthBirth = cal.get(Calendar.MONTH);
+		int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
+        // 计算整岁数
+		Integer age = yearNow - yearBirth;
+		if (monthNow <= monthBirth) {
+			if (monthNow == monthBirth) {
+				if (dayOfMonthNow < dayOfMonthBirth) {
+					// 当前日期在生日之前,年龄减一
+					age--;
+				}
+			} else {
+				age--;
+			}
+		}
+
+		return age.toString();
+	}
 }

--
Gitblit v1.9.1