1:- module(uk_plate_age,
2 [ plate_period/3, 3 plate_period_text/2, 4 age_identifier_period/3, 5 prefix_period/3, 6 identifiers_for_year/2 7 ]).
32:- use_module(library(lists)).
39age_identifier_period(Id, Start, End) :-
40 ( integer(Id) -> true ; between(2, 99, Id) ),
41 Id >= 2, Id =< 99, Id =\= 50,
42 ( Id < 50
43 -> Y is 2000 + Id, Start = Y-3, End = Y-8
44 ; Y is 1950 + Id, Y1 is Y + 1, Start = Y-9, End = Y1-2
45 ).
51prefix_period(Letter, Start, End) :-
52 prefix(Letter, Start, End).
53
54prefix('A', 1983-8, 1984-7).
55prefix('B', 1984-8, 1985-7).
56prefix('C', 1985-8, 1986-7).
57prefix('D', 1986-8, 1987-7).
58prefix('E', 1987-8, 1988-7).
59prefix('F', 1988-8, 1989-7).
60prefix('G', 1989-8, 1990-7).
61prefix('H', 1990-8, 1991-7).
62prefix('J', 1991-8, 1992-7).
63prefix('K', 1992-8, 1993-7).
64prefix('L', 1993-8, 1994-7).
65prefix('M', 1994-8, 1995-7).
66prefix('N', 1995-8, 1996-7).
67prefix('P', 1996-8, 1997-7).
68prefix('R', 1997-8, 1998-7).
69prefix('S', 1998-8, 1999-2).
70prefix('T', 1999-3, 1999-8).
71prefix('V', 1999-9, 2000-2).
72prefix('W', 2000-3, 2000-8).
73prefix('X', 2000-9, 2001-2).
74prefix('Y', 2001-3, 2001-8).
81plate_period(Plate, Start, End) :-
82 normalise(Plate, Codes),
83 ( current_format(Codes, Id)
84 -> age_identifier_period(Id, Start, End)
85 ; prefix_format(Codes, Letter)
86 -> prefix_period(Letter, Start, End)
87 ).
93plate_period_text(Plate, Text) :-
94 plate_period(Plate, SY-SM, EY-EM),
95 month_name(SM, SN),
96 month_name(EM, EN),
97 format(string(Text), "~w ~w to ~w ~w", [SN, SY, EN, EY]).
103identifiers_for_year(2001, [51]) :- !.
104identifiers_for_year(Year, [March, Sept]) :-
105 integer(Year), Year >= 2002, Year =< 2049,
106 March is Year - 2000,
107 Sept is Year - 1950.
108
109normalise(Plate, Codes) :-
110 string_upper(Plate, Upper),
111 string_codes(Upper, All),
112 exclude(==(0' ), All, Codes).
113
114current_format([A,B,D1,D2,C,D,E], Id) :-
115 maplist(letter, [A,B,C,D,E]),
116 digit(D1), digit(D2),
117 Id is (D1 - 0'0) * 10 + (D2 - 0'0).
118
119prefix_format([L|Rest], Letter) :-
120 letter(L),
121 append(Digits, [C1,C2,C3], Rest),
122 length(Digits, N), N >= 1, N =< 3,
123 maplist(digit, Digits),
124 maplist(letter, [C1,C2,C3]), !,
125 atom_codes(Letter, [L]).
126
127letter(C) :- C >= 0'A, C =< 0'Z.
128digit(C) :- C >= 0'0, C =< 0'9.
129
130month_name(1, 'January'). month_name(2, 'February').
131month_name(3, 'March'). month_name(4, 'April').
132month_name(5, 'May'). month_name(6, 'June').
133month_name(7, 'July'). month_name(8, 'August').
134month_name(9, 'September'). month_name(10, 'October').
135month_name(11, 'November'). month_name(12, 'December')
Registration periods from UK (GB) number plate age identifiers
Works out when a vehicle was first registered from the age identifier on a Great Britain number plate, following DVLA leaflet INF104.
Periods are returned as Year-Month pairs, so
24gives2024-3to2024-8. A plate only gives a window: private plates can make a vehicle look older (never newer), imports are dated from their first UK registration, and dateless or Northern Ireland plates carry no identifier. The date of first registration on the V5C is the exact answer.