Skip to content

Commit

Permalink
Update AAMVAtoJSON.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenquan authored Jun 14, 2019
1 parent 97fa72e commit 5c209b0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions AAMVAtoJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function AAMVAtoJSON(data) {
IIN,
AAMVAVersion,
jurisdictionVersion,
numberOfEntries ] = data.match(/^@\n.\r(ANSI |AAMVA)(\d{6})(\d{2})(\d{2})(\d{2})/);
numberOfEntries ] = data.match(/^@\n.\r(ANSI |AAMVA)(\d{6})(\d{2})(\d{2})(\d{2})/) || [ ]
if (!__data) return null

var obj = {
Expand All @@ -24,7 +24,7 @@ function AAMVAtoJSON(data) {
for (let i = 0; i < obj.header.numberOfEntries; i++) {
let entryOffset = 21 + i * 10
let [ __entry, subfileType, offset, length ]
= data.substring(entryOffset, entryOffset + 10).match(/(.{2})(\d{4})(\d{4})/)
= data.substring(entryOffset, entryOffset + 10).match(/(.{2})(\d{4})(\d{4})/) || [ ]
if (i === 0) obj.files = [ ]
obj.files.push(subfileType)
obj[subfileType] = data.substring(+offset + 2, +offset + +length).trim().split(/\n\r?/).reduce((p, c) => {
Expand All @@ -36,12 +36,12 @@ function AAMVAtoJSON(data) {
// Convert date string (in local timezone) into Javascript UTC time
function convertAAMVADate(str, country) {
function convertAAMVADateUSA(str) {
const [ __str, month, day, year ] = str.match(/(\d{2})(\d{2})(\d{4})/)
const [ __str, month, day, year ] = str.match(/(\d{2})(\d{2})(\d{4})/) || [ ]
if (!__str) return null
return new Date(year, month-1, day).getTime()
}
function convertAAMVADateCAN(str) {
const [ __str, year, month, day ] = str.match(/(\d{4})(\d{2})(\d{2})/)
const [ __str, year, month, day ] = str.match(/(\d{4})(\d{2})(\d{2})/) || [ ]
if (!__str) return null
return new Date(year, month-1, day).getTime()
}
Expand Down

0 comments on commit 5c209b0

Please sign in to comment.