Skip to main content
Version: v8001

Check if a document is expired

BlinkID does not report expiry status directly. Instead, it returns the expiry date that it read from the document, and you decide whether the document is expired by comparing that date against today.

Two result fields drive this logic:

  • dateOfExpiry: a date result with optional numeric year, month, and day parts, plus the printed originalString and a successfullyParsed flag.
  • dateOfExpiryPermanent: a boolean that is true when the document never expires.

Determining expiry​

Apply the following logic to the scanning result:

  1. If dateOfExpiryPermanent is true, the document never expires, so treat it as not expired.
  2. If dateOfExpiry was not parsed into numeric parts (no year), you cannot determine the expiry status.
  3. Otherwise, build a date from year, month, and day and compare it against today.
type ExpiryStatus = "expired" | "valid" | "unknown";

function checkExpiry(result): ExpiryStatus {
if (result.dateOfExpiryPermanent) {
return "valid";
}

const expiry = result.dateOfExpiry;
if (!expiry?.successfullyParsed || expiry.year === undefined) {
return "unknown";
}

// Month is 1-12, so subtract one for the JS Date constructor.
const expiryDate = new Date(expiry.year, (expiry.month ?? 1) - 1, expiry.day ?? 1);
return expiryDate < new Date() ? "expired" : "valid";
}

blinkId.addOnResultCallback((result) => {
console.log("Expiry status:", checkExpiry(result));

void blinkId.destroy();
});

Handling the unknown case​

When the expiry date cannot be parsed, fall back to the printed text in originalString rather than rejecting the document outright. This lets you surface the raw expiry text to a reviewer or to the user for manual confirmation.

blinkId.addOnResultCallback((result) => {
if (!result.dateOfExpiryPermanent && !result.dateOfExpiry?.successfullyParsed) {
console.log("Could not parse expiry. Printed text:", result.dateOfExpiry?.originalString?.latin?.value);
}

void blinkId.destroy();
});