UNPKG

missing-native-js-functions

Version:

mnJSf that should be the base library for every JS project

125 lines 4.93 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var Util_1 = require("./Util"); (0, Util_1.define)(Date, { nowSeconds: function () { return Math.floor(Date.now() / 1000); }, }); (0, Util_1.define)(Date.prototype, { setTimezone: function (timezone) { this.setTime(new Date(this.toLocaleString("en-US", { timeZone: timezone, })).getTime()); return this; }, isInPast: function () { var today = new Date(); today.setHours(0, 0, 0, 0); return this < today; }, set: function (opts) { if (opts.timezone) return this.setTimezone(opts.timezone).set(__assign(__assign({}, opts), { timezone: undefined })); if (opts.time != null) this.setTime(opts.time); if (opts.utc != null) { if (opts.year != null) this.setUTCFullYear(opts.year); if (opts.month != null) this.setUTCMonth(opts.month); if (opts.date != null) this.setUTCDate(opts.date); if (opts.hours != null) this.setUTCHours(opts.hours); if (opts.minutes != null) this.setUTCMinutes(opts.minutes); if (opts.seconds != null) this.setUTCSeconds(opts.seconds); if (opts.milliseconds != null) this.setUTCMilliseconds(opts.milliseconds); } else { if (opts.year != null) this.setFullYear(opts.year); if (opts.month != null) this.setMonth(opts.month); if (opts.date != null) this.setDate(opts.date); if (opts.hours != null) this.setHours(opts.hours); if (opts.minutes != null) this.setMinutes(opts.minutes); if (opts.seconds != null) this.setSeconds(opts.seconds); if (opts.milliseconds != null) this.setMilliseconds(opts.milliseconds); } return this; }, add: function (opts) { if (opts.timezone) return this.setTimezone(opts.timezone).set(__assign(__assign({}, opts), { timezone: undefined })); if (opts.utc) delete opts.utc; if (opts.time != null) opts.time += this.getTime(); if (opts.year != null) opts.year += this.getFullYear(); if (opts.month != null) opts.month += this.getMonth(); if (opts.date != null) opts.date += this.getDate(); if (opts.hours != null) opts.hours += this.getHours(); if (opts.minutes != null) opts.minutes += this.getMinutes(); if (opts.seconds != null) opts.seconds += this.getSeconds(); if (opts.milliseconds != null) opts.milliseconds += this.getMilliseconds(); return this.set(opts); }, addYear: function (years, month, date) { if (month === void 0) { month = 0; } if (date === void 0) { date = 0; } return this.setFullYear(this.getFullYear() + years, this.getMonth() + month, this.getDate() + date); }, addMonth: function (months, date) { if (date === void 0) { date = 0; } return this.setMonth(this.getMonth() + months, this.getDate() + date); }, addDate: function (days) { return this.setDate(this.getDate() + days); }, addHours: function (hours, minutes, seconds, milliseconds) { if (minutes === void 0) { minutes = 0; } if (seconds === void 0) { seconds = 0; } if (milliseconds === void 0) { milliseconds = 0; } return this.setHours(this.getHours() + hours, this.getMinutes() + minutes, this.getSeconds() + seconds, this.getMilliseconds() + milliseconds); }, addMinutes: function (minutes, seconds, milliseconds) { if (seconds === void 0) { seconds = 0; } if (milliseconds === void 0) { milliseconds = 0; } return this.setMinutes(this.getMinutes() + minutes, this.getSeconds() + seconds, this.getMilliseconds() + milliseconds); }, addSeconds: function (seconds, milliseconds) { if (milliseconds === void 0) { milliseconds = 0; } return this.setSeconds(this.getSeconds() + seconds, this.getMilliseconds() + milliseconds); }, addMilliseconds: function (milliseconds) { return this.setMilliseconds(this.getMilliseconds() + milliseconds); }, }); //# sourceMappingURL=Date.js.map