Archived
1
0
Fork 0
This repository has been archived on 2024-02-06. You can view files and clone it, but cannot push or open issues or pull requests.
api-ts-gen/dist/utils/FullDate.js

99 lines
3.2 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function removeTime(date) {
return new Date(date.setHours(0, 0, 0, 0));
}
var FullDate = /** @class */ (function () {
function FullDate() {
var argv = [];
for (var _i = 0; _i < arguments.length; _i++) {
argv[_i] = arguments[_i];
}
this._date = removeTime((function () {
var _a, _b, _c;
if (argv.length == 0)
return new Date();
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);
}
return new Date(argv[0], ((_b = argv[1]) !== null && _b !== void 0 ? _b : 1) - 1, (_c = argv[2]) !== null && _c !== void 0 ? _c : 1);
})());
}
FullDate.prototype.toString = function () {
2020-04-06 01:09:37 +09:00
var d = this._date;
var f = function (s) { return ('0' + s).slice(-2); };
return d.getFullYear() + "-" + f(d.getMonth() + 1) + "-" + f(d.getDate());
};
FullDate.prototype.toJSON = function () {
return this.toString();
};
FullDate.prototype.valueOf = function () {
return this._date.valueOf();
};
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 () {
return this._date.getFullYear();
2020-04-06 01:09:37 +09:00
},
// setter
set: function (val) {
this._date.setFullYear(val);
2020-04-06 01:09:37 +09:00
},
enumerable: true,
configurable: true
});
Object.defineProperty(FullDate.prototype, "month", {
get: function () {
return this._date.getMonth() + 1;
2020-04-06 01:09:37 +09:00
},
set: function (val) {
this._date.setMonth(val - 1);
2020-04-06 01:09:37 +09:00
},
enumerable: true,
configurable: true
});
Object.defineProperty(FullDate.prototype, "day", {
get: function () {
return this._date.getDate();
2020-04-06 01:09:37 +09:00
},
set: function (val) {
this._date.setDate(val);
2020-04-06 01:09:37 +09:00
},
enumerable: true,
configurable: true
});
Object.defineProperty(FullDate.prototype, "dayOfWeek", {
get: function () {
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);
};
FullDate.prototype.distanceFrom = function (d0) {
return (this.valueOf() - d0.valueOf()) / 86400e3;
};
return FullDate;
}());
exports.FullDate = FullDate;