UNPKG

@rnaga/wp-node

Version:

👉 **[View Full Documentation at rnaga.github.io/wp-node →](https://rnaga.github.io/wp-node/)**

72 lines (71 loc) • 2.79 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var DateTime_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateTime = void 0; const moment_1 = __importDefault(require("moment")); const constants_1 = require("../constants"); const component_1 = require("../decorators/component"); const vars_1 = require("./vars"); let DateTime = class DateTime { static { DateTime_1 = this; } vars; #gmtDate; static mySQLFormat = "YYYY-MM-DD HH:mm:ss"; constructor(vars, initialDate) { this.vars = vars; this.#gmtDate = initialDate ? moment_1.default .utc(initialDate) .subtract(this.vars.TIME_OFFSET_MINUTES, "minutes") : moment_1.default.utc(); } get currentLocalTime() { return moment_1.default .utc() .add(this.vars.TIME_OFFSET_MINUTES, "minutes") .toDate() .getTime(); } get currentDate() { return new Date(this.currentLocalTime); } get time() { const localDateTime = moment_1.default.utc(this.#gmtDate); return localDateTime.add(this.vars.TIME_OFFSET_MINUTES, "minutes"); } format(v) { return this.time.format(v); } gmtFormat(v) { this.#gmtDate.format(v); } get mySQLDatetime() { return this.format(DateTime_1.mySQLFormat); } get mySQLGMTDatetime() { return this.#gmtDate.format(DateTime_1.mySQLFormat); } greaterThan(gmtDate) { return moment_1.default.utc(this.#gmtDate) > moment_1.default.utc(gmtDate); } isFuture() { return moment_1.default.utc(this.#gmtDate) > moment_1.default.utc(); } }; exports.DateTime = DateTime; exports.DateTime = DateTime = DateTime_1 = __decorate([ (0, component_1.component)({ scope: constants_1.Scope.Transient }), __metadata("design:paramtypes", [vars_1.Vars, Object]) ], DateTime);