feat(home,my): 首页和我的页从缓存回显用户信息
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
90f84cc7df
commit
e25e797b35
@@ -38,3 +38,17 @@ export const parseIdCard = (idCard: string): IdCardParsed => {
|
||||
sex,
|
||||
}
|
||||
}
|
||||
|
||||
/** 从生日字符串(YYYY-MM-DD)计算周岁 */
|
||||
export const calcAge = (birthday: string): number => {
|
||||
if (!birthday) return 0
|
||||
const parts = birthday.split('-').map(Number)
|
||||
const [year, month, day] = parts
|
||||
if (!year || !month || !day) return 0
|
||||
const now = new Date()
|
||||
let age = now.getFullYear() - year
|
||||
const nowMonth = now.getMonth() + 1
|
||||
const nowDay = now.getDate()
|
||||
if (nowMonth < month || (nowMonth === month && nowDay < day)) age -= 1
|
||||
return Math.max(0, age)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user