{"record":{"id":"39aeed612ceb4696","repo":"bchavez/Bogus","slug":"pesel-for-the-year-below-1800-is-invalid","errorCode":null,"errorMessage":"PESEL for the year below 1800 is invalid.","messagePattern":"PESEL for the year below 1800 is invalid\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Extensions/Poland/ExtensionsForPoland.cs","lineNumber":42,"sourceCode":"      {\n         return (string)value;\n      }\n\n      return new StringBuilder()\n         .AppendPeselDateOfBirth(person.DateOfBirth)\n         .Append(person.Random.Number(9))\n         .Append(person.Random.Number(9))\n         .Append(person.Random.Number(9))\n         .AppendPeselGender(person)\n         .AppendPeselChecksum()\n         .ToString();\n   }\n\n   private static StringBuilder AppendPeselDateOfBirth(this StringBuilder builder, DateTime dateOfBirth)\n   {\n      int monthShift = dateOfBirth.Year switch\n      {\n         < 1800 => throw new ArgumentOutOfRangeException(\"PESEL for the year below 1800 is invalid.\"),\n         < 1900 => 80,\n         < 2000 => 0,\n         < 2100 => 20,\n         < 2200 => 40,\n         < 2300 => 60,\n         _ => throw new ArgumentOutOfRangeException(\"PESEL for year above 2300 is invalid.\"),\n      };\n\n      return builder\n         .Append((dateOfBirth.Year % 100).ToString(\"00\"))\n         .Append((dateOfBirth.Month+monthShift).ToString(\"00\"))\n         .Append(dateOfBirth.Day.ToString(\"00\"));\n   }\n\n   private static StringBuilder AppendPeselGender(this StringBuilder builder, Person person)\n   {\n      return builder\n         .Append(person.Gender == Name.Gender.Male","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Extensions/Poland/ExtensionsForPoland.cs#L24-L60","documentation":"ExtensionsForPoland.Pesel encodes the birth date with a month shift that only has defined buckets for years 1800-2299 (in 100-year steps). A year below 1800 throws ArgumentOutOfRangeException. This is a hard limit of the PESEL encoding scheme.","triggerScenarios":"Calling person.Pesel() on a Person whose DateOfBirth.Year is less than 1800.","commonSituations":"Historical test data with a pre-1800 birth date, or an accidental DateTime.MinValue / default(DateTime) DateOfBirth.","solutions":["Ensure Person.DateOfBirth.Year is >= 1800 before calling Pesel.","Generate birth dates with f.Date.Between(new DateTime(1900,1,1), DateTime.Today).","Guard against default(DateTime) (year 1) being assigned to DateOfBirth."],"exampleFix":"// before\nperson.DateOfBirth = new DateTime(1750, 1, 1);\nvar pesel = person.Pesel();\n\n// after\nperson.DateOfBirth = f.Date.Between(new DateTime(1960,1,1), DateTime.Today);\nvar pesel = person.Pesel();","handlingStrategy":"validation","validationCode":"int year = person.DateOfBirth.Year;\nif (year < 1800)\n    throw new ArgumentOutOfRangeException(nameof(year), \"PESEL requires year >= 1800.\");\nvar pesel = person.Pesel();","typeGuard":"static bool PeselYearOk(int y) => y >= 1800 && y < 2300;","tryCatchPattern":null,"preventionTips":["Guard against default(DateTime) (year 1) leaking into DateOfBirth.","Use realistic recent birth dates for fixtures.","The PESEL lower bound is a hard 1800."],"tags":["poland","pesel","date-validation","national-id"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}