/// <summary> /// Converts the value of the current <see cref="SwedishPersonalIdentityNumber" /> object to its equivalent short string representation. /// Format is YYMMDDXSSSC, for example <example>990807-2391</example> or <example>120211+9986</example>. /// </summary> /// <param name="date">The date to decide wheter the person is older than 100 years. That decides the delimiter (- or +).</param> public string ToShortString(DateTime date) { var dateOfBirth = SwedishPersonalIdentityNumberDateCalculations.GetDateOfBirth(Year, Month, Day); var age = SwedishPersonalIdentityNumberDateCalculations.GetAge(dateOfBirth, date); var delimiter = age >= 100 ? '+' : '-'; var twoDigitYear = Year % 100; return($"{twoDigitYear:D2}{Month:D2}{Day:D2}{delimiter}{SerialNumber:D3}{Checksum}"); }
/// <summary> /// Get the age of the person according to the date in the personal identity number. /// Not always the actual date of birth due to lmitied amount of personal identity numbers per day. /// </summary> /// <param name="personalIdentityNumber"></param> /// <param name="date">The date when to calulate the age.</param> /// <returns></returns> public static int GetAgeHint(this SwedishPersonalIdentityNumber personalIdentityNumber, DateTime date) { return(SwedishPersonalIdentityNumberDateCalculations.GetAge(personalIdentityNumber.GetDateOfBirthHint(), date)); }
/// <summary> /// Date of birth for the person according to the personal identity number. /// Not always the actual date of birth due to lmitied amount of personal identity numbers per day. /// </summary> public static DateTime GetDateOfBirthHint(this SwedishPersonalIdentityNumber personalIdentityNumber) { return(SwedishPersonalIdentityNumberDateCalculations.GetDateOfBirth(personalIdentityNumber.Year, personalIdentityNumber.Month, personalIdentityNumber.Day)); }