public static void validateIndividnummer(String fodselsnummer) { var fnr = new Fodselsnummer(fodselsnummer); if (fnr.getCentury() == null) { throw new ArgumentException(ERROR_INVALID_INDIVIDNUMMER + fodselsnummer); } }
public void testGetCentury() { sut = new Fodselsnummer("01016666609"); Assert.AreEqual("18", sut.getCentury()); sut = new Fodselsnummer("01016633301"); Assert.AreEqual("19", sut.getCentury()); sut = new Fodselsnummer("01019196697"); Assert.AreEqual("19", sut.getCentury()); sut = new Fodselsnummer("01013366671"); Assert.AreEqual("20", sut.getCentury()); // DNumber... sut = new Fodselsnummer("41016666609"); Assert.AreEqual("18", sut.getCentury()); sut = new Fodselsnummer("01015466609"); Assert.AreEqual("18", sut.getCentury()); sut = new Fodselsnummer("41016633301"); Assert.AreEqual("19", sut.getCentury()); sut = new Fodselsnummer("41019196697"); Assert.AreEqual("19", sut.getCentury()); sut = new Fodselsnummer("41013366671"); Assert.AreEqual("20", sut.getCentury()); }
public static void validateChecksums(String fodselsnummer) { var fnr = new Fodselsnummer(fodselsnummer); int k1 = CalculateFirstChecksumDigit(fnr); int k2 = CalculateSecondChecksumDigit(fnr); if (k1 != fnr.getChecksumDigit1() || k2 != fnr.getChecksumDigit2()) { throw new ArgumentException(InvalidChecksumErrorMessage + fodselsnummer); } }
public static void validateDate(String fodselsnummer) { var fnr = new Fodselsnummer(fodselsnummer); try { var dateString = fnr.getDateAndMonth() + fnr.getCentury() + fnr.get2DigitBirthYear(); DateTime.ParseExact(dateString, DATE_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None); } catch (Exception) { throw new ArgumentException(ERROR_INVALID_DATE + fodselsnummer); } }
public static void validateChecksums(String fodselsnummer) { var fnr = new Fodselsnummer(fodselsnummer); int k1 = CalculateFirstChecksumDigit(fnr); int k2 = CalculateSecondChecksumDigit(fnr); if (k1 != fnr.getChecksumDigit1() || k2 != fnr.getChecksumDigit2()) { throw new ArgumentException(ERROR_INVALID_CHECKSUM + fodselsnummer); } }
/** * Returns a List with with VALID Fodselsnummer instances for a given Date. * * @param date The Date instance * @return A List with Fodelsnummer instances */ public static List <Fodselsnummer> GetManyFodselsnummerForDate(DateTime date, bool dNumber = false) { if (date == null) { throw new ArgumentException(); } var century = GetCentury(date); var dateString = date.ToString("ddMMyy"); if (dNumber) { var day = date.Day + 40; dateString = $"{day}{date.ToString("MMyy")}"; } var result = new List <Fodselsnummer>(); for (int i = 999; i >= 0; i--) { var sb = new StringBuilder(dateString); if (i < 10) { sb.Append("00"); } else if (i < 100) { sb.Append("0"); } sb.Append(i); var fodselsnummer = new Fodselsnummer(sb.ToString()); try { sb.Append(FodselsnummerValidator.CalculateFirstChecksumDigit(fodselsnummer)); fodselsnummer = new Fodselsnummer(sb.ToString()); sb.Append(FodselsnummerValidator.CalculateSecondChecksumDigit(fodselsnummer)); fodselsnummer = new Fodselsnummer(sb.ToString()); var centuryByIndividnummer = fodselsnummer.GetCentury(); if (centuryByIndividnummer != null && centuryByIndividnummer.Equals(century) && FodselsnummerValidator.IsValid(fodselsnummer.GetValue())) { result.Add(fodselsnummer); } } catch (ArgumentException) { continue; } } return(result); }
/** * Returns a List with with VALID Fodselsnummer instances for a given Date. * * @param date The Date instance * @return A List with Fodelsnummer instances */ public static List<Fodselsnummer> getManyFodselsnummerForDate(DateTime date) { if (date == null) { throw new ArgumentException(); } var century = getCentury(date); var dateString = date.ToString("ddMMyy"); var result = new List<Fodselsnummer>(); for (int i = 999; i >= 0; i--) { var sb = new StringBuilder(dateString); if (i < 10) { sb.Append("00"); } else if (i < 100) { sb.Append("0"); } sb.Append(i); var fodselsnummer = new Fodselsnummer(sb.ToString()); try { sb.Append(FodselsnummerValidator.CalculateFirstChecksumDigit(fodselsnummer)); fodselsnummer = new Fodselsnummer(sb.ToString()); sb.Append(FodselsnummerValidator.CalculateSecondChecksumDigit(fodselsnummer)); fodselsnummer = new Fodselsnummer(sb.ToString()); var centuryByIndividnummer = fodselsnummer.getCentury(); if (centuryByIndividnummer != null && centuryByIndividnummer.Equals(century) && FodselsnummerValidator.IsValid(fodselsnummer.GetValue())) { result.Add(fodselsnummer); } } catch (ArgumentException) { continue; } } return result; }
public void testGetDateOfBirthDNumber() { sut = new Fodselsnummer(VALID_D_FODSELSNUMMER); Assert.AreEqual("010101", sut.getDateOfBirth()); }
public void testGetBirthYear() { Assert.AreEqual("1901", sut.getBirthYear()); sut = new Fodselsnummer(VALID_D_FODSELSNUMMER); Assert.AreEqual("1901", sut.getBirthYear()); }
public void setUpValidFodselsnummer() { sut = new Fodselsnummer(VALID_FODSELSNUMMER); }
public void testIsMaleDNumber() { sut = new Fodselsnummer(VALID_D_FODSELSNUMMER); Assert.AreEqual(false, sut.isMale()); }
public void testGetDayInMonth() { Assert.AreEqual("01", sut.getDayInMonth()); sut = new Fodselsnummer(VALID_D_FODSELSNUMMER); Assert.AreEqual("01", sut.getDayInMonth()); }
internal static int CalculateFirstChecksumDigit(Fodselsnummer fodselsnummer) { return(CalculateMod11CheckSum(K1_WEIGHTS, fodselsnummer)); }
internal static int CalculateSecondChecksumDigit(Fodselsnummer fodselsnummer) { return(CalculateMod11CheckSum(GetMod11Weights(fodselsnummer), fodselsnummer)); }
internal static int CalculateFirstChecksumDigit(Fodselsnummer fodselsnummer) { return CalculateMod11CheckSum(K1_WEIGHTS, fodselsnummer); }
internal static int CalculateSecondChecksumDigit(Fodselsnummer fodselsnummer) { return CalculateMod11CheckSum(GetMod11Weights(fodselsnummer), fodselsnummer); }