UNPKG

mindee

Version:

Mindee Client Library for Node.js

36 lines (35 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateField = void 0; const field_1 = require("./field"); /** * A field containing a date value. */ class DateField extends field_1.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(); } } exports.DateField = DateField;