{"record":{"id":"cd85e4b2656270a8","repo":"bchavez/Bogus","slug":"can-only-accept-registration-dates-between-earlie","errorCode":null,"errorMessage":"Can only accept registration dates between {EarliestRegistration:yyyy-MM-dd} and {LatestRegistration:yyyy-MM-dd}.","messagePattern":"Can only accept registration dates between (.+?) and (.+?)\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Extensions/UnitedKingdom/ExtensionsForGreatBritainRegistrationPlate.cs","lineNumber":134,"sourceCode":"               return 'C';\n            case 6:\n            case 12:\n               return 'D';\n         }\n\n         throw new InvalidOperationException(\n            $\"This code path should never be accessible. {nameof(primaryLocation)}={primaryLocation}; {nameof(registrationDate)}={registrationDate:O}\");\n      }\n      \n      char[] secondaryLocationChoices = SecondaryLocations[primaryLocation];\n      char secondaryLocation = vehicle.Random.ArrayElement(secondaryLocationChoices);\n      return secondaryLocation;\n   }\n\n   private static DateTime GenerateRegistrationDate(Vehicle vehicle, DateTime dateFrom, DateTime dateTo)\n   {\n      if (dateFrom < EarliestRegistration || dateFrom > LatestRegistration)\n          throw new ArgumentOutOfRangeException(nameof(dateFrom), $\"Can only accept registration dates between {EarliestRegistration:yyyy-MM-dd} and {LatestRegistration:yyyy-MM-dd}.\");\n      if (dateTo < EarliestRegistration || dateTo > LatestRegistration)\n          throw new ArgumentOutOfRangeException(nameof(dateTo),$\"Can only accept registration dates between {EarliestRegistration:yyyy-MM-dd} and {LatestRegistration:yyyy-MM-dd}.\");\n      \n      // Swap the values of the to and from dates if they're the wrong way around.\n      if (dateFrom > dateTo)\n      {\n         // Syntax not supported: (dateFrom, dateTo) = (dateTo, dateFrom);\n         DateTime valueHolder = dateFrom;\n         dateFrom = dateTo;\n         dateTo = valueHolder;\n      }\n      \n      dateFrom = dateFrom.Date;\n      dateTo = dateTo.Date;\n      int duration = (int) (dateTo - dateFrom).TotalDays;\n      int offset = vehicle.Random.Int(0, duration);\n      DateTime registrationDate = dateFrom.AddDays(offset);\n      return registrationDate;","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Extensions/UnitedKingdom/ExtensionsForGreatBritainRegistrationPlate.cs#L116-L152","documentation":"ExtensionsForGreatBritainRegistrationPlate only models the current UK plate scheme, so GenerateRegistrationDate rejects any dateFrom outside 2001-09-01 to 2051-02-28. The bounds are the static fields EarliestRegistration (StartOfCurrentStyle = 2001-09-01) and LatestRegistration (2051-02-28). This overload throws on the dateFrom argument specifically.","triggerScenarios":"Calling vehicle.GbRegistrationPlate(dateFrom, dateTo) where dateFrom is before 2001-09-01 or after 2051-02-28 (e.g. new DateTime(1999,1,1) or new DateTime(2060,1,1)).","commonSituations":"Generating plates for older vehicles (pre-2001 suffix/prefix plates) which this extension does not support, or passing a future date range past 2051.","solutions":["Pass a dateFrom within 2001-09-01 .. 2051-02-28.","Use a recent range such as new DateTime(2010,1,1) to DateTime.Today.","For pre-2001 vehicles, use a different generator - this API only covers the current scheme."],"exampleFix":"// before\nvar plate = vehicle.GbRegistrationPlate(new DateTime(1995,1,1), new DateTime(2000,1,1));\n\n// after\nvar plate = vehicle.GbRegistrationPlate(new DateTime(2010,1,1), new DateTime(2020,1,1));","handlingStrategy":"validation","validationCode":"DateTime earliest = new(2001,9,1), latest = new(2051,2,28);\nif (dateFrom < earliest || dateFrom > latest)\n    throw new ArgumentOutOfRangeException(nameof(dateFrom), $\"Use {earliest:yyyy-MM-dd}..{latest:yyyy-MM-dd}\");\nvar plate = vehicle.GbRegistrationPlate(dateFrom, dateTo);","typeGuard":"static bool WithinGbWindow(DateTime d) => d >= new DateTime(2001,9,1) && d <= new DateTime(2051,2,28);","tryCatchPattern":null,"preventionTips":["Use a recent in-window range (e.g. 2010..today).","This extension only models the post-2001 current scheme.","Clamp both dateFrom and dateTo independently before calling."],"tags":["united-kingdom","registration-plate","date-validation","vehicle"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}