{"record":{"id":"7e96ffa238233de4","repo":"bchavez/Bogus","slug":"nameof-year-must-be-between-1858-and-2057","errorCode":null,"errorMessage":"{nameof(year)} must be between 1858 and 2057.","messagePattern":"(.+?) must be between 1858 and 2057\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Extensions/Denmark/ExtensionsForDenmark.cs","lineNumber":108,"sourceCode":"            break;\n         case >= 1900 and <= 1936:\n            from = 0;\n            to = 3999;\n            break;\n         case >= 1937 and <= 1999:\n            from = 0;\n            to = 4999;\n            break;\n         case >= 2000 and <= 2036:\n            from = 4000;\n            to = 9999;\n            break;\n         case >= 2037 and <= 2057:\n            from = 5000;\n            to = 9999;\n            break;\n         default:\n            throw new ArgumentOutOfRangeException(nameof(year), $\"{nameof(year)} must be between 1858 and 2057.\");\n      }\n\n      int individualNumber = gender == DataSets.Name.Gender.Female ? r.Even(from, to) : r.Odd(from, to);\n\n      return individualNumber.ToString(\"D4\");\n   }\n\n   private static string GenerateIndividualThreeDigitNumber(Randomizer r, int year)\n   {\n      int from;\n      int to;\n\n      switch( year )\n      {\n         case >= 1858 and <= 1899:\n            from = 500;\n            to = 899;\n            break;","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Extensions/Denmark/ExtensionsForDenmark.cs#L90-L126","documentation":"GenerateIndividualFourDigitNumber (used by Person.Cpr when validChecksum=false) maps a birth year to an individual-number range and only covers 1858-1899, 1900-1936, 1937-1999, 2000-2036, 2037-2057. Any other year throws ArgumentOutOfRangeException. This is the Danish CPR numbering scheme's own era limits, not an arbitrary Bogus choice.","triggerScenarios":"Calling person.Cpr(validChecksum: false) on a Person whose DateOfBirth.Year is below 1858 or above 2057.","commonSituations":"Overriding Person.DateOfBirth to a far-future date (e.g. DateTime.Now.AddYears(50)) or a pre-1858 date for historical fixtures, then generating a Danish CPR.","solutions":["Constrain Person.DateOfBirth to a year between 1858 and 2057 before calling Cpr.","Generate the birth date via the Date dataset, e.g. f.Date.Between(new DateTime(1900,1,1), DateTime.Today).","Avoid hand-setting DateOfBirth to dates outside the supported era."],"exampleFix":"// before\nperson.DateOfBirth = new DateTime(2100, 1, 1);\nvar cpr = person.Cpr(validChecksum: false);\n\n// after\nperson.DateOfBirth = f.Date.Between(new DateTime(1960,1,1), DateTime.Today);\nvar cpr = person.Cpr(validChecksum: false);","handlingStrategy":"validation","validationCode":"int year = person.DateOfBirth.Year;\nif (year < 1858 || year > 2057)\n    throw new ArgumentOutOfRangeException(nameof(year), \"Danish CPR requires 1858-2057.\");\nvar cpr = person.Cpr(validChecksum: false);","typeGuard":"static bool DanishCprYearOk(int y) => y >= 1858 && y <= 2057;","tryCatchPattern":null,"preventionTips":["Generate birth dates inside 1858-2057 with f.Date.Between.","Audit any code that overwrites Person.DateOfBirth.","Remember the validChecksum=false path uses the 4-digit individual number with the same era limits."],"tags":["denmark","cpr","date-validation","national-id"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}