UNPKG

@ncodedcode/ncode_react_lib

Version:

ncode react application context library

102 lines 3.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JSDateDating = void 0; var JSDateDating = (function () { function JSDateDating() { this._date = new Date(); } JSDateDating.prototype.now = function () { this._date = new Date(); return this; }; JSDateDating.prototype.create = function (m) { this._date = new Date(m); return this; }; JSDateDating.prototype.fromDate = function (d) { this._date = new Date(d); return this; }; JSDateDating.prototype.parse = function (date) { var adjusted = date.replace(/(\+\d{2})(\d{2})$/, "$1:$2"); this._date = new Date(adjusted); return this; }; JSDateDating.prototype.year = function () { return this._date.getFullYear(); }; JSDateDating.prototype.month = function () { return this._date.getMonth() + 1; }; JSDateDating.prototype.day = function () { return this._date.getDate(); }; JSDateDating.prototype.dayOfWeek = function () { return this._date.getDay(); }; JSDateDating.prototype.hour = function () { return this._date.getHours(); }; JSDateDating.prototype.minute = function () { return this._date.getMinutes(); }; JSDateDating.prototype.second = function () { return this._date.getSeconds(); }; JSDateDating.prototype.isPast = function () { var now = new Date().getTime(); var target = this.millis(); return now > target; }; JSDateDating.prototype.isFuture = function () { var now = new Date().getTime(); var target = this.millis(); return now < target; }; JSDateDating.prototype.compare = function (target) { var me = this.millis(); var other = target.millis(); var diff = me - other; if (diff === 0) return 0; return diff < 0 ? -1 : 1; }; JSDateDating.prototype.isoFormat = function () { return this._date.toISOString(); }; JSDateDating.prototype.format = function (f) { return f .replace("yyyy", "".concat(this.year())) .replace("YYYY", "".concat(this.year())) .replace("MM", "".concat(this.month())) .replace("DD", "".concat(this.day())) .replace("HH", "".concat(this.hour())) .replace("mm", "".concat(this.minute())) .replace("ss", "".concat(this.second())); }; JSDateDating.prototype.millis = function () { return this._date.getTime(); }; JSDateDating.prototype.toDate = function () { return this._date; }; JSDateDating.prototype.currentTimezone = function () { return Intl.DateTimeFormat().resolvedOptions().timeZone; }; JSDateDating.prototype.addDayTo = function (day) { this._date.setDate(this._date.getDate() + day); return this; }; JSDateDating.prototype.diff = function (date, unit, float) { throw new Error("diff not supported"); return -1; }; JSDateDating.prototype.duration = function (millisecond, format, unit) { if (unit === void 0) { unit = "milliseconds"; } throw new Error("duration not supported"); return ""; }; return JSDateDating; }()); exports.JSDateDating = JSDateDating; //# sourceMappingURL=JSDateDating.js.map