This commit is contained in:
liuhongrui
2025-03-03 16:31:00 +08:00
parent b8ced534fe
commit f3d71f95e7
3 changed files with 39 additions and 6 deletions

View File

@@ -20,4 +20,12 @@ public interface IPatientService extends IService<Patient> {
* @return 出生日
*/
Date extractBirthday(String idCard);
/**
* 判断日期是否为未来时间
*
* @param date 字符串日期
* @return 是/否
*/
boolean isFuture(String date);
}

View File

@@ -23,7 +23,7 @@ public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> impl
/**
* 从身份证号码中提取生日
*
*
* @param idCard 身份证号
* @return 出生日
*/
@@ -43,4 +43,23 @@ public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> impl
return Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
@Override
public boolean isFuture(String dateString) {
// 创建 DateTimeFormatter 对象,并设置所需的日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
try {
// 解析字符串为 LocalDate 对象
LocalDate dateToCheck = LocalDate.parse(dateString, formatter);
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 检查日期是否是未来的时间
return dateToCheck.isAfter(currentDate);
} catch (Exception e) {
e.printStackTrace();
// 解析失败或其他异常,返回 false 或根据需要处理异常
return false;
}
}
}