سؤال

I'm trying to code a simple VIN (ISO 3779) decoder: manufacturer and model year. I'm having some issues w/ decoding the model year, though. According to Wikipedia:

For passenger cars, and for multipurpose passenger vehicles and trucks with a gross vehicle weight rating of 10,000 lb (4,500 kg) or less, if position 7 is numeric, the model year in position 10 of the VIN refers to a year in the range 1980–2009. If position 7 is alphabetic, the model year in position 10 of VIN refers to a year in the range 2010–2039.

My car's VIN (Model Year 2012) has the following info:

VSS---1--C-------
12345678901234567

Manufacturer: SEAT, Model Year: 1982 (Some online VIN decoders give me 1982, some others give me 2012)

How can I modify my decoder so I get this right, other than doing a nasty if (Manufacturer == "SEAT") Year += 30;hack?

هل كانت مفيدة؟

المحلول

Having read positions 7 and 10, here's some PHP code:

$year = date_1980_2009( $position_10 );  # use your current date function...

if ( preg_match( "/^[A-Z]$/i", $position_7 ) ) $year += 30;  # add 30 years if 7 is alphabetic

Having said that, your car doesn't seem to be following the rules. Exceptional cases require coding exceptions -- which aren't hacks. Sorry.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top