UNPKG

mindee

Version:

Mindee Client Library for Node.js

32 lines (31 loc) 1.08 kB
import { Field } from "./field.js"; /** * A field containing a date value. */ export class DateField extends Field { /** * @param {BaseFieldConstructor} constructor Constructor parameters. */ constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId, }) { super({ prediction, valueKey, reconstructed, pageId }); if ("is_computed" in prediction) { this.isComputed = prediction["is_computed"]; } if (typeof this.value === "string") { this.dateObject = new Date(this.value); if (isNaN(this.dateObject.valueOf())) { this.dateObject = undefined; this.confidence = 0.0; this.value = undefined; } else { this.dateObject.setUTCHours(0, 0, 0, 0); } } } static compareDates(date1, date2) { return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate(); } }