From 0692f4289ee0046a50602adc065f1ececa90dfea Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期日, 19 十月 2025 16:54:29 +0800
Subject: [PATCH] Merge branch 'dev-1.2.0.1' of http://120.26.58.240:8888/r/flexJobAdminBClient into dev-1.2.0.1
---
src/utils/common/common.ts | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/src/utils/common/common.ts b/src/utils/common/common.ts
index b05dfc3..9965df0 100644
--- a/src/utils/common/common.ts
+++ b/src/utils/common/common.ts
@@ -106,3 +106,27 @@
export function filterNumbersFromString(str: string) {
return str.replace(/\D/g, '');
}
+
+export function calculateAge(idCardNumber) {
+ if (BoleRegExp.RegIDCard.test(idCardNumber)) {
+ const birthDateStr = idCardNumber.match(/(\d{6})(\d{8})/)[2];
+ const birthDate = new Date(
+ birthDateStr.substring(0, 4),
+ birthDateStr.substring(4, 6) - 1,
+ birthDateStr.substring(6, 8)
+ );
+
+ // Calculate age
+ const today = new Date();
+ const age =
+ today.getFullYear() -
+ birthDate.getFullYear() -
+ (today.getMonth() < birthDate.getMonth() ||
+ (today.getMonth() === birthDate.getMonth() && today.getDate() < birthDate.getDate())
+ ? 1
+ : 0);
+
+ return age;
+ }
+ return null;
+}
--
Gitblit v1.9.1