Browse Source

年龄按照生日计算调整

master
杨雷 4 weeks ago
parent
commit
8228d16a53
2 changed files with 23 additions and 1 deletions
  1. +22
    -0
      TelpoPush.Ability.Worker/Common/TimeHelper.cs
  2. +1
    -1
      TelpoPush.Ability.Worker/Service/Biz/PsychHealthData.cs

+ 22
- 0
TelpoPush.Ability.Worker/Common/TimeHelper.cs View File

@@ -60,5 +60,27 @@ namespace TelpoPush.Ability.Worker.Common
return dt.ToString("yyyy-MM-dd");
}

/// <summary>
/// 计算年龄
/// </summary>
/// <param name="birthday">出生日期(生日)</param>
/// <param name="isYear">年:true(年);false(月,天)</param>
/// <returns></returns>
public static int GetAge(DateTime birthday,bool isYear=false) {

DateTime today = DateTime.Today;
if (today < birthday)
return 0;

// 计算年龄
int age = today.Year - birthday.Year;
if (!isYear)
{
// 如果今天日期还没到生日日期,则年龄减一
if (today.Month < birthday.Month || (today.Month == birthday.Month && today.Day < birthday.Day))
age--;
}
return age;
}
}
}

+ 1
- 1
TelpoPush.Ability.Worker/Service/Biz/PsychHealthData.cs View File

@@ -122,7 +122,7 @@ namespace TelpoPush.Ability.Worker.Service.Biz
//65~74 1 1
//>= 75 2 2
bool isAge = false;
int age = DateTime.Now.Year - person.birth.Value.Year;
int age = TimeHelper.GetAge(person.birth.Value);// DateTime.Now.Year - person.birth.Value.Year;
if (age >= 65 && age <= 74)
{
hisDate.birth = [1, 1];


Loading…
Cancel
Save