{"record":{"id":"6ed61b1b69b6c35a","repo":"bchavez/Bogus","slug":"nameof-p-dateofbirth-year-must-be-between-1900","errorCode":null,"errorMessage":"{nameof(p.DateOfBirth.Year)} must be between 1900 and 2099.","messagePattern":"(.+?) must be between 1900 and 2099\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Extensions/Romania/ExtensionsForRomania.cs","lineNumber":61,"sourceCode":"      var randomizer = p.Random;\n\n      var judet = randomizer.Enum<RomanianBirthCounty>();\n      int sex;\n      //persoanele rezidente\n      //sex = p.Gender == Gender.Male ? 7 : 8;\n      switch (p.DateOfBirth.Year)\n      {\n         case >= 1900 and <= 1999:\n            sex = p.Gender == Name.Gender.Male ? 1 : 2;\n            break;\n         case >= 1800 and <= 1899:\n            sex = p.Gender == Name.Gender.Male ? 3 : 4;\n            break;\n         case >= 2000 and <= 2099:\n            sex = p.Gender == Name.Gender.Male ? 5 : 6;\n            break;\n         default:\n            throw new ArgumentOutOfRangeException(nameof(p.DateOfBirth.Year),\n               $\"{nameof(p.DateOfBirth.Year)} must be between 1900 and 2099.\");\n      }\n\n      var seq = randomizer.Int(1, 999);\n      var cnp = sex +\n                p.DateOfBirth.ToString(\"yyMMdd\") +\n                ((int)judet).ToString(\"00\") +\n                seq.ToString(\"000\");\n\n      var checksum = GenerateChecksum(cnp);\n      var final = cnp + checksum;\n      p.context[Key] = final;\n\n      return final;\n   }\n\n   private static string GenerateChecksum(string cnp)\n   {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Extensions/Romania/ExtensionsForRomania.cs#L43-L79","documentation":"ExtensionsForRomania.Cnp encodes the sex/century digit and handles three eras: 1800-1899, 1900-1999, 2000-2099. A year outside 1800-2099 throws ArgumentOutOfRangeException. NOTE: the message text claims 'must be between 1900 and 2099' but the code actually supports 1800-2099 - the message omits the 1800-1899 era that IS handled, so treat the message as misleading and use 1800-2099 as the real supported window.","triggerScenarios":"Calling person.Cnp() on a Person whose DateOfBirth.Year is below 1800 or above 2099.","commonSituations":"Setting DateOfBirth to a far-future date (>2099) or pre-1800 historical date, then generating a Romanian CNP. Developers may also be confused by the message claiming 1900 is the lower bound when 1800-1899 actually works.","solutions":["Keep Person.DateOfBirth.Year within 1800-2099 (despite the message saying 1900-2099).","Use f.Date.Between(new DateTime(1900,1,1), DateTime.Today) for realistic dates.","Avoid future years beyond 2099 for Romanian CNP fixtures."],"exampleFix":"// before\nperson.DateOfBirth = new DateTime(2100, 1, 1);\nvar cnp = person.Cnp();\n\n// after\nperson.DateOfBirth = f.Date.Between(new DateTime(1970,1,1), DateTime.Today);\nvar cnp = person.Cnp();","handlingStrategy":"validation","validationCode":"// Real supported window is 1800-2099 despite the message text.\nint year = person.DateOfBirth.Year;\nif (year < 1800 || year > 2099)\n    throw new ArgumentOutOfRangeException(nameof(year), \"Romanian CNP requires 1800-2099.\");\nvar cnp = person.Cnp();","typeGuard":"static bool CnpYearOk(int y) => y >= 1800 && y <= 2099;","tryCatchPattern":null,"preventionTips":["Trust the 1800-2099 range, not the message's 1900-2099 claim.","Avoid future years > 2099 and pre-1800 dates.","File/track the message-text bug so the lower bound is not misread."],"tags":["romania","cnp","date-validation","national-id","message-bug"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}