java-localdatetime
Version:
### 日期工具库
99 lines (98 loc) • 3.77 kB
JavaScript
"use strict";
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalTime = void 0;
var moment = require("moment");
var abstractDate_1 = require("./abstractDate");
var consts_1 = require("./consts");
var LocalTime = /** @class */ (function (_super) {
__extends(LocalTime, _super);
function LocalTime(date) {
var _this = _super.call(this) || this;
_this.momentDate = date ? moment(date, consts_1.TIME_FORMAT) : moment();
return _this;
}
LocalTime.of = function (hour, minute, second) {
return new LocalTime(hour + ':' + minute + ':' + second);
};
LocalTime.now = function () {
var _a = _super.buildDateProperty.call(this), hour = _a.hour, minute = _a.minute, second = _a.second;
return LocalTime.of(hour, minute, second);
};
LocalTime.parse = function (date) {
return new LocalTime(date);
};
LocalTime.parseMoment = function (moment) {
var _a = this.buildDateProperty(moment), hour = _a.hour, minute = _a.minute, second = _a.second;
return LocalTime.of(hour, minute, second);
};
LocalTime.prototype.clone = function () {
return LocalTime.parseMoment(this.momentDate.clone());
};
LocalTime.prototype.getHour = function () {
return this.hour();
};
LocalTime.prototype.getMinute = function () {
return this.minute();
};
LocalTime.prototype.getSecond = function () {
return this.second();
};
LocalTime.prototype.isBefore = function (date) {
return this.momentDate.isBefore(date.momentDate);
};
LocalTime.prototype.isAfter = function (date) {
return this.momentDate.isAfter(date.momentDate);
};
LocalTime.prototype.plusHour = function (hour) {
return LocalTime.parseMoment(this.clone().momentDate.add(hour, 'h'));
};
LocalTime.prototype.minusHour = function (hour) {
return this.plusHour(hour * -1);
};
LocalTime.prototype.plusMinute = function (minute) {
return LocalTime.parseMoment(this.clone().momentDate.add(minute, 'm'));
};
LocalTime.prototype.minusMinute = function (minute) {
return this.plusMinute(minute * -1);
};
LocalTime.prototype.plusSecond = function (second) {
return LocalTime.parseMoment(this.clone().momentDate.add(second, 's'));
};
LocalTime.prototype.minusSecond = function (second) {
return this.plusSecond(second * -1);
};
LocalTime.prototype.format = function (pattern) {
if (pattern === void 0) { pattern = consts_1.TIME_FORMAT; }
return this.momentDate.format(pattern);
};
LocalTime.prototype.setHour = function (hour) {
this.momentDate.hour(hour);
return this;
};
LocalTime.prototype.setMinute = function (minute) {
this.momentDate.minute(minute);
return this;
};
LocalTime.prototype.setSecond = function (second) {
this.momentDate.second(second);
return this;
};
LocalTime.prototype.toString = function () {
return this.format();
};
return LocalTime;
}(abstractDate_1.AbstractDate));
exports.LocalTime = LocalTime;