@drewsonne/maya-dates
Version:
Typescript package to manipulate dates in the Maya Calendar
86 lines • 3.45 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var longcount_operation_1 = __importDefault(require("./longcount-operation"));
var LongcountSubtraction = (function (_super) {
__extends(LongcountSubtraction, _super);
function LongcountSubtraction() {
return _super !== null && _super.apply(this, arguments) || this;
}
LongcountSubtraction.prototype.equals = function () {
var _a;
var _b = this.buildOperationComponents(), aParts = _b[0], bParts = _b[1], isInverted = _b[2];
var newParts = aParts.map(function (p, i) {
var bPart = bParts[i];
if (typeof p === 'number') {
if (typeof bPart === 'number') {
return (isInverted ? (bPart - p) : (p - bPart));
}
else {
throw new Error("'bPart' is not a number");
}
}
else {
throw new Error("'p' is not a number");
}
});
var carry = 0;
var i = 0;
while (i < newParts.length || carry < 0) {
newParts[i] += carry;
carry = 0;
while (newParts[i] < 0) {
carry -= 1;
var nextPositionMonthLength = (i === 1) ? 15 : 20;
newParts[i] += nextPositionMonthLength;
}
i += 1;
}
for (i = newParts.length - 1; i > 0; i -= 1) {
if (newParts[i] === 0) {
newParts.pop();
}
else {
i = 0;
}
}
var newLC = new ((_a = this.LcClass).bind.apply(_a, __spreadArray([void 0], newParts, false)))();
newLC.isPositive = !isInverted;
return newLC;
};
LongcountSubtraction.prototype.equal = function (other) {
if (other instanceof LongcountSubtraction) {
return this.a.equal(other.a) && this.b.equal(other.b);
}
return false;
};
return LongcountSubtraction;
}(longcount_operation_1.default));
exports.default = LongcountSubtraction;
//# sourceMappingURL=longcount-subtraction.js.map