image-classifier-ts
Version:
Command line tool to auto-classify images, renaming them with appropriate labels. Uses Node and Google Vision API.
113 lines • 4.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleDate = void 0;
// Simple date to the nearest day, and month is 1-based (!).
var SimpleDate = /** @class */ (function () {
function SimpleDate(month, day, year, hour, minute, second) {
if (hour === void 0) { hour = 0; }
if (minute === void 0) { minute = 0; }
if (second === void 0) { second = 0; }
this.month = month;
this.day = day;
this.year = year;
this.hour = hour;
this.minute = minute;
this.second = second;
}
SimpleDate.fromDate = function (date) {
var newDate = new SimpleDate(date.getMonth() + 1, date.getDate(), date.getFullYear(), date.getHours(), date.getMinutes(), date.getSeconds());
return newDate;
};
// Format: 'm/d/y' OR 'm/d/yTh:m:s'
SimpleDate.parseFromMDY = function (text) {
var dateAndTimeParts = text.split("T");
var datePart = dateAndTimeParts[0];
var parts = datePart.split("/");
var month = SimpleDate.parsePart(parts, 0);
var day = SimpleDate.parsePart(parts, 1);
var year = SimpleDate.parsePart(parts, 2);
var hour = 0;
var minute = 0;
var second = 0;
if (dateAndTimeParts[1]) {
var timePart = dateAndTimeParts[1];
var timeParts = timePart.split(":");
hour = SimpleDate.parsePart(timeParts, 0);
minute = SimpleDate.parsePart(timeParts, 1);
second = SimpleDate.parsePart(timeParts, 2);
}
return new SimpleDate(month, day, year, hour, minute, second);
};
// Format: 'Y:M:D' OR 'Y:M:D H:M:S'
SimpleDate.parseFromExifDate = function (dateValueYMD) {
var dateAndTimeParts = dateValueYMD.split(" ");
var datePart = dateAndTimeParts[0];
var parts = datePart.split(":");
var year = SimpleDate.parsePart(parts, 0);
var month = SimpleDate.parsePart(parts, 1);
var day = SimpleDate.parsePart(parts, 2);
var hour = 0;
var minute = 0;
var second = 0;
if (dateAndTimeParts[1]) {
var timePart = dateAndTimeParts[1];
var timeParts = timePart.split(":");
hour = SimpleDate.parsePart(timeParts, 0);
minute = SimpleDate.parsePart(timeParts, 1);
second = SimpleDate.parsePart(timeParts, 2);
}
return new SimpleDate(month, day, year, hour, minute, second);
};
SimpleDate.parsePart = function (partArray, partIndex) {
return parseInt(partArray[partIndex], 10);
};
SimpleDate.prototype.isEqualTo = function (other) {
var thisDate = this.toDate();
var otherDate = other.toDate();
return thisDate <= otherDate && thisDate >= otherDate;
};
SimpleDate.prototype.compareTo = function (other) {
var thisDate = this.toDate();
var otherDate = other.toDate();
return thisDate.getTime() - otherDate.getTime();
};
SimpleDate.prototype.isGreaterThan = function (other) {
var thisDate = this.toDate();
var otherDate = other.toDate();
return thisDate > otherDate;
};
SimpleDate.prototype.isLessThan = function (other) {
var thisDate = this.toDate();
var otherDate = other.toDate();
return thisDate < otherDate;
};
SimpleDate.prototype.isLessThanOrEqualTo = function (other) {
var thisDate = this.toDate();
var otherDate = other.toDate();
return thisDate <= otherDate;
};
SimpleDate.prototype.nextDay = function () {
var thisDate = this.toDate();
// time part will be 00:00:00
var nextDate = new Date(this.year, this.month - 1, this.day);
nextDate.setDate(thisDate.getDate() + 1);
var next = SimpleDate.fromDate(nextDate);
return next;
};
SimpleDate.prototype.toDate = function () {
return new Date(this.year, this.month - 1, this.day, this.hour, this.minute, this.second);
};
// US date format
SimpleDate.prototype.toString = function () {
return "".concat(this.month, "/").concat(this.day, "/").concat(this.year, "T").concat(this.asTwoDigits(this.hour), ":").concat(this.asTwoDigits(this.minute), ":").concat(this.asTwoDigits(this.second));
};
SimpleDate.prototype.asTwoDigits = function (value) {
return ("0" + value).slice(-2);
};
SimpleDate.prototype.toStringDateOnly = function () {
return "".concat(this.month, "/").concat(this.day, "/").concat(this.year);
};
return SimpleDate;
}());
exports.SimpleDate = SimpleDate;
//# sourceMappingURL=SimpleDate.js.map