private bool IsDateValid(string cpr) { var day = int.Parse(cpr.Substring(0, 2)); var month = int.Parse(cpr.Substring(2, 2)); var yearEnding = int.Parse(cpr.Substring(4, 2)); var serialNumber = int.Parse(cpr.Substring(6, 1)); var year = _serialNumberParser.Parse(yearEnding, serialNumber); return(day > 0 && day <= DateTime.DaysInMonth(year, month)); }
//Extracting Birthdate from CPR number public DateTime GetBirthDate(string cpr) { var trimmedCpr = Parse(cpr); if (string.IsNullOrEmpty(trimmedCpr)) { throw new ArgumentException("The cpr number was invalid", nameof(cpr)); } var day = int.Parse(cpr.Substring(0, 2)); var month = int.Parse(cpr.Substring(2, 2)); var yearEnding = int.Parse(cpr.Substring(4, 2)); var serialNumber = int.Parse(cpr.Substring(6, 1)); var birthYear = _serialParser.Parse(yearEnding, serialNumber); return(new DateTime(birthYear, month, day)); }