//using System.Application.Columns; //using System.Properties; //namespace System.Application //{ // public static class BirthDateHelper // { // /// // /// 一年的天数 // /// // const double AYearDays = 365.2425; // /// // /// 将年龄值转换为用于UI显示的字符串 // /// // /// // /// // public static string ToString(byte age) // { // return string.Format(SR.Age_, age); // } // static byte AgeResultCorrect(int age) // { // if (age < 0) // { // return 0; // } // else if (age > IBirthDate.HumanMaxAge) // { // return IBirthDate.HumanMaxAge; // } // else // { // return (byte)age; // } // } // /// // /// (仅适用于客户端计算)根据生日计算年龄 // /// // /// // /// // /// // static byte CalcAge(DateTime? birthDate, byte def = 0) // { // if (birthDate.HasValue) // { // var today = DateTime.Today; // var birth = new DateTime(birthDate.Value.Year, // birthDate.Value.Month, // birthDate.Value.Day, // 0, 0, 0, // today.Kind); // var age = (int)((today - birth).TotalDays / AYearDays); // return AgeResultCorrect(age); // } // return def; // } // /// // /// (仅适用于服务端计算)根据生日及用户所在时区计算年龄 // /// // /// // /// // /// // /// // static byte CalcAge(long timeZoneTicks, DateTime? birthDate, byte def = 0) // { // if (birthDate.HasValue) // { // var offset = new TimeSpan(timeZoneTicks); // var today = DateTimeOffset.Now; // var birth = new DateTimeOffset(birthDate.Value.Year, // birthDate.Value.Month, // birthDate.Value.Day, // 0, 0, 0, // offset); // var age = (int)((today - birth).TotalDays / AYearDays); // return AgeResultCorrect(age); // } // return def; // } // /// // /// (仅适用于服务端计算)根据生日及用户所在时区计算年龄 // /// // /// // /// // public static byte CalcAge(this IBirthDateTimeZoneTicks birthDate) // => CalcAge(birthDate.TimeZoneTicks, birthDate.BirthDate); // /// // /// (仅适用于客户端计算)根据生日计算年龄并转换为用于UI显示的字符串 // /// // /// // /// // public static string CalcAgeToString(this IBirthDateCalcAge birthDate) // { // var age = CalcAge(birthDate.BirthDate, birthDate.Age); // return ToString(age); // } // } //}