2020-04-05 00:57:34 +09:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2020-04-09 19:45:32 +09:00
|
|
|
function removeTime(date) {
|
2020-05-24 01:23:42 +09:00
|
|
|
return new Date(date.setHours(0, 0, 0, 0));
|
2020-04-09 19:45:32 +09:00
|
|
|
}
|
2020-04-05 00:57:34 +09:00
|
|
|
var FullDate = /** @class */ (function () {
|
|
|
|
function FullDate() {
|
|
|
|
var argv = [];
|
|
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
|
|
argv[_i] = arguments[_i];
|
|
|
|
}
|
2020-04-09 19:45:32 +09:00
|
|
|
this._date = removeTime((function () {
|
|
|
|
var _a, _b, _c;
|
|
|
|
if (argv.length == 0)
|
|
|
|
return new Date();
|
2020-04-05 00:57:34 +09:00
|
|
|
if (argv.length == 1) {
|
|
|
|
var arg = argv[0];
|
|
|
|
if (arg instanceof FullDate)
|
|
|
|
return new Date(+arg);
|
|
|
|
if (arg instanceof Date)
|
|
|
|
return arg;
|
|
|
|
if (typeof arg === 'string') {
|
|
|
|
var tokens = (_a = /^(\d+)-(\d+)-(\d+)$/g.exec(arg)) === null || _a === void 0 ? void 0 : _a.slice(1, 4);
|
|
|
|
if (tokens)
|
|
|
|
return new Date(+tokens[0], +tokens[1] - 1, +tokens[2]);
|
|
|
|
}
|
|
|
|
return new Date(arg);
|
|
|
|
}
|
2020-04-09 19:45:32 +09:00
|
|
|
return new Date(argv[0], ((_b = argv[1]) !== null && _b !== void 0 ? _b : 1) - 1, (_c = argv[2]) !== null && _c !== void 0 ? _c : 1);
|
|
|
|
})());
|
2020-04-05 00:57:34 +09:00
|
|
|
}
|
|
|
|
FullDate.prototype.toString = function () {
|
2020-04-06 01:09:37 +09:00
|
|
|
var d = this._date;
|
2020-04-05 00:57:34 +09:00
|
|
|
var f = function (s) { return ('0' + s).slice(-2); };
|
2020-05-24 01:23:42 +09:00
|
|
|
return d.getFullYear() + "-" + f(d.getMonth() + 1) + "-" + f(d.getDate());
|
2020-04-05 00:57:34 +09:00
|
|
|
};
|
|
|
|
FullDate.prototype.toJSON = function () {
|
|
|
|
return this.toString();
|
|
|
|
};
|
|
|
|
FullDate.prototype.valueOf = function () {
|
2020-04-09 19:45:32 +09:00
|
|
|
return this._date.valueOf();
|
2020-04-05 00:57:34 +09:00
|
|
|
};
|
2020-04-06 01:09:37 +09:00
|
|
|
Object.defineProperty(FullDate.prototype, "date", {
|
|
|
|
// getter
|
|
|
|
get: function () {
|
|
|
|
return new Date(this._date);
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
Object.defineProperty(FullDate.prototype, "year", {
|
|
|
|
get: function () {
|
2020-05-24 01:23:42 +09:00
|
|
|
return this._date.getFullYear();
|
2020-04-06 01:09:37 +09:00
|
|
|
},
|
|
|
|
// setter
|
|
|
|
set: function (val) {
|
2020-05-24 01:23:42 +09:00
|
|
|
this._date.setFullYear(val);
|
2020-04-06 01:09:37 +09:00
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
Object.defineProperty(FullDate.prototype, "month", {
|
|
|
|
get: function () {
|
2020-05-24 01:23:42 +09:00
|
|
|
return this._date.getMonth() + 1;
|
2020-04-06 01:09:37 +09:00
|
|
|
},
|
|
|
|
set: function (val) {
|
2020-05-24 01:23:42 +09:00
|
|
|
this._date.setMonth(val - 1);
|
2020-04-06 01:09:37 +09:00
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
Object.defineProperty(FullDate.prototype, "day", {
|
|
|
|
get: function () {
|
2020-05-24 01:23:42 +09:00
|
|
|
return this._date.getDate();
|
2020-04-06 01:09:37 +09:00
|
|
|
},
|
|
|
|
set: function (val) {
|
2020-05-24 01:23:42 +09:00
|
|
|
this._date.setDate(val);
|
2020-04-06 01:09:37 +09:00
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
Object.defineProperty(FullDate.prototype, "dayOfWeek", {
|
|
|
|
get: function () {
|
2020-05-24 01:23:42 +09:00
|
|
|
return this._date.getDay();
|
2020-04-06 01:09:37 +09:00
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
// func
|
|
|
|
FullDate.prototype.advance = function (period) {
|
|
|
|
return new FullDate(this._date.valueOf() + period * 86400e3);
|
2020-04-05 00:57:34 +09:00
|
|
|
};
|
2020-04-09 19:45:32 +09:00
|
|
|
FullDate.prototype.distanceFrom = function (d0) {
|
|
|
|
return (this.valueOf() - d0.valueOf()) / 86400e3;
|
|
|
|
};
|
2020-04-05 00:57:34 +09:00
|
|
|
return FullDate;
|
|
|
|
}());
|
|
|
|
exports.FullDate = FullDate;
|