From 994cc72e1d533a93dce9a13490247f5fdefb32b8 Mon Sep 17 00:00:00 2001 From: Daniel Triendl Date: Thu, 19 Mar 2026 13:40:50 +0100 Subject: [PATCH] Bump version to 9.3.0 --- 3CX_TAPI.user.js | 1511 ++++++++++++++++++++++------------------------ 1 file changed, 723 insertions(+), 788 deletions(-) diff --git a/3CX_TAPI.user.js b/3CX_TAPI.user.js index 16d7667..ef5f6da 100644 --- a/3CX_TAPI.user.js +++ b/3CX_TAPI.user.js @@ -1,31 +1,29 @@ // ==UserScript== // @name 3CX TAPI // @namespace http://cp-solutions.at -// @version 9.2.2 +// @version 9.3.0 // @author Daniel Triendl -// @copyright Copyright 2021 CP Solutions GmbH +// @copyright Copyright CP Solutions GmbH // @source https://source.cp-austria.at/CPATRD/3cx_tapi.git -// @downloadURL https://source.cp-austria.at/CPATRD/3cx_tapi/raw/branch/master/3CX_TAPI.user.js +// @downloadURL https://source.cp-austria.at/CPATRD/3cx_tapi.git/raw/branch/master/3CX_TAPI.user.js // @match https://192.168.0.154:5001/* // @match https://cpsolution.my3cx.at:5001/* // @require https://cdn.jsdelivr.net/gh/CoeJoder/waitForKeyElements.js@v1.2/waitForKeyElements.js -// @require https://cdn.jsdelivr.net/npm/axios@undefined/dist/axios.min.js -// @require https://cdn.jsdelivr.net/npm/axios-userscript-adapter@undefined/dist/axiosGmxhrAdapter.min.js // @grant GM.xmlHttpRequest // @grant GM.notification // @grant GM.getValue // @grant GM.setValue -// @connect cpatapi.cpsrvweb2016.cp-austria.at +// @connect 3cxtapi.cp-austria.at // @run-at document-end // ==/UserScript== /******/ (() => { // webpackBootstrap +/******/ "use strict"; /******/ var __webpack_modules__ = ({ -/***/ "./node_modules/css-loader/dist/runtime/api.js": -/***/ ((module) => { +/***/ "./node_modules/css-loader/dist/runtime/api.js" +(module) { -"use strict"; /* @@ -112,376 +110,22 @@ module.exports = function (cssWithMappingToString) { return list; }; -/***/ }), +/***/ }, -/***/ "./node_modules/css-loader/dist/runtime/noSourceMaps.js": -/***/ ((module) => { +/***/ "./node_modules/css-loader/dist/runtime/noSourceMaps.js" +(module) { -"use strict"; module.exports = function (i) { return i[1]; }; -/***/ }), +/***/ }, -/***/ "./node_modules/dayjs/dayjs.min.js": -/***/ (function(module) { +/***/ "./node_modules/css-loader/dist/cjs.js!./src/search.css" +(module, __webpack_exports__, __webpack_require__) { -!function (t, e) { - true ? module.exports = e() : 0; -}(this, function () { - "use strict"; - - var t = 1e3, - e = 6e4, - n = 36e5, - r = "millisecond", - i = "second", - s = "minute", - u = "hour", - a = "day", - o = "week", - f = "month", - h = "quarter", - c = "year", - d = "date", - l = "Invalid Date", - $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, - y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, - M = { - name: "en", - weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), - months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), - ordinal: function (t) { - var e = ["th", "st", "nd", "rd"], - n = t % 100; - return "[" + t + (e[(n - 20) % 10] || e[n] || e[0]) + "]"; - } - }, - m = function (t, e, n) { - var r = String(t); - return !r || r.length >= e ? t : "" + Array(e + 1 - r.length).join(n) + t; - }, - v = { - s: m, - z: function (t) { - var e = -t.utcOffset(), - n = Math.abs(e), - r = Math.floor(n / 60), - i = n % 60; - return (e <= 0 ? "+" : "-") + m(r, 2, "0") + ":" + m(i, 2, "0"); - }, - m: function t(e, n) { - if (e.date() < n.date()) return -t(n, e); - var r = 12 * (n.year() - e.year()) + (n.month() - e.month()), - i = e.clone().add(r, f), - s = n - i < 0, - u = e.clone().add(r + (s ? -1 : 1), f); - return +(-(r + (n - i) / (s ? i - u : u - i)) || 0); - }, - a: function (t) { - return t < 0 ? Math.ceil(t) || 0 : Math.floor(t); - }, - p: function (t) { - return { - M: f, - y: c, - w: o, - d: a, - D: d, - h: u, - m: s, - s: i, - ms: r, - Q: h - }[t] || String(t || "").toLowerCase().replace(/s$/, ""); - }, - u: function (t) { - return void 0 === t; - } - }, - g = "en", - D = {}; - D[g] = M; - var p = function (t) { - return t instanceof _; - }, - S = function t(e, n, r) { - var i; - if (!e) return g; - if ("string" == typeof e) { - var s = e.toLowerCase(); - D[s] && (i = s), n && (D[s] = n, i = s); - var u = e.split("-"); - if (!i && u.length > 1) return t(u[0]); - } else { - var a = e.name; - D[a] = e, i = a; - } - return !r && i && (g = i), i || !r && g; - }, - w = function (t, e) { - if (p(t)) return t.clone(); - var n = "object" == typeof e ? e : {}; - return n.date = t, n.args = arguments, new _(n); - }, - O = v; - O.l = S, O.i = p, O.w = function (t, e) { - return w(t, { - locale: e.$L, - utc: e.$u, - x: e.$x, - $offset: e.$offset - }); - }; - var _ = function () { - function M(t) { - this.$L = S(t.locale, null, !0), this.parse(t); - } - var m = M.prototype; - return m.parse = function (t) { - this.$d = function (t) { - var e = t.date, - n = t.utc; - if (null === e) return new Date(NaN); - if (O.u(e)) return new Date(); - if (e instanceof Date) return new Date(e); - if ("string" == typeof e && !/Z$/i.test(e)) { - var r = e.match($); - if (r) { - var i = r[2] - 1 || 0, - s = (r[7] || "0").substring(0, 3); - return n ? new Date(Date.UTC(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s)) : new Date(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s); - } - } - return new Date(e); - }(t), this.$x = t.x || {}, this.init(); - }, m.init = function () { - var t = this.$d; - this.$y = t.getFullYear(), this.$M = t.getMonth(), this.$D = t.getDate(), this.$W = t.getDay(), this.$H = t.getHours(), this.$m = t.getMinutes(), this.$s = t.getSeconds(), this.$ms = t.getMilliseconds(); - }, m.$utils = function () { - return O; - }, m.isValid = function () { - return !(this.$d.toString() === l); - }, m.isSame = function (t, e) { - var n = w(t); - return this.startOf(e) <= n && n <= this.endOf(e); - }, m.isAfter = function (t, e) { - return w(t) < this.startOf(e); - }, m.isBefore = function (t, e) { - return this.endOf(e) < w(t); - }, m.$g = function (t, e, n) { - return O.u(t) ? this[e] : this.set(n, t); - }, m.unix = function () { - return Math.floor(this.valueOf() / 1e3); - }, m.valueOf = function () { - return this.$d.getTime(); - }, m.startOf = function (t, e) { - var n = this, - r = !!O.u(e) || e, - h = O.p(t), - l = function (t, e) { - var i = O.w(n.$u ? Date.UTC(n.$y, e, t) : new Date(n.$y, e, t), n); - return r ? i : i.endOf(a); - }, - $ = function (t, e) { - return O.w(n.toDate()[t].apply(n.toDate("s"), (r ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e)), n); - }, - y = this.$W, - M = this.$M, - m = this.$D, - v = "set" + (this.$u ? "UTC" : ""); - switch (h) { - case c: - return r ? l(1, 0) : l(31, 11); - case f: - return r ? l(1, M) : l(0, M + 1); - case o: - var g = this.$locale().weekStart || 0, - D = (y < g ? y + 7 : y) - g; - return l(r ? m - D : m + (6 - D), M); - case a: - case d: - return $(v + "Hours", 0); - case u: - return $(v + "Minutes", 1); - case s: - return $(v + "Seconds", 2); - case i: - return $(v + "Milliseconds", 3); - default: - return this.clone(); - } - }, m.endOf = function (t) { - return this.startOf(t, !1); - }, m.$set = function (t, e) { - var n, - o = O.p(t), - h = "set" + (this.$u ? "UTC" : ""), - l = (n = {}, n[a] = h + "Date", n[d] = h + "Date", n[f] = h + "Month", n[c] = h + "FullYear", n[u] = h + "Hours", n[s] = h + "Minutes", n[i] = h + "Seconds", n[r] = h + "Milliseconds", n)[o], - $ = o === a ? this.$D + (e - this.$W) : e; - if (o === f || o === c) { - var y = this.clone().set(d, 1); - y.$d[l]($), y.init(), this.$d = y.set(d, Math.min(this.$D, y.daysInMonth())).$d; - } else l && this.$d[l]($); - return this.init(), this; - }, m.set = function (t, e) { - return this.clone().$set(t, e); - }, m.get = function (t) { - return this[O.p(t)](); - }, m.add = function (r, h) { - var d, - l = this; - r = Number(r); - var $ = O.p(h), - y = function (t) { - var e = w(l); - return O.w(e.date(e.date() + Math.round(t * r)), l); - }; - if ($ === f) return this.set(f, this.$M + r); - if ($ === c) return this.set(c, this.$y + r); - if ($ === a) return y(1); - if ($ === o) return y(7); - var M = (d = {}, d[s] = e, d[u] = n, d[i] = t, d)[$] || 1, - m = this.$d.getTime() + r * M; - return O.w(m, this); - }, m.subtract = function (t, e) { - return this.add(-1 * t, e); - }, m.format = function (t) { - var e = this, - n = this.$locale(); - if (!this.isValid()) return n.invalidDate || l; - var r = t || "YYYY-MM-DDTHH:mm:ssZ", - i = O.z(this), - s = this.$H, - u = this.$m, - a = this.$M, - o = n.weekdays, - f = n.months, - h = function (t, n, i, s) { - return t && (t[n] || t(e, r)) || i[n].slice(0, s); - }, - c = function (t) { - return O.s(s % 12 || 12, t, "0"); - }, - d = n.meridiem || function (t, e, n) { - var r = t < 12 ? "AM" : "PM"; - return n ? r.toLowerCase() : r; - }, - $ = { - YY: String(this.$y).slice(-2), - YYYY: O.s(this.$y, 4, "0"), - M: a + 1, - MM: O.s(a + 1, 2, "0"), - MMM: h(n.monthsShort, a, f, 3), - MMMM: h(f, a), - D: this.$D, - DD: O.s(this.$D, 2, "0"), - d: String(this.$W), - dd: h(n.weekdaysMin, this.$W, o, 2), - ddd: h(n.weekdaysShort, this.$W, o, 3), - dddd: o[this.$W], - H: String(s), - HH: O.s(s, 2, "0"), - h: c(1), - hh: c(2), - a: d(s, u, !0), - A: d(s, u, !1), - m: String(u), - mm: O.s(u, 2, "0"), - s: String(this.$s), - ss: O.s(this.$s, 2, "0"), - SSS: O.s(this.$ms, 3, "0"), - Z: i - }; - return r.replace(y, function (t, e) { - return e || $[t] || i.replace(":", ""); - }); - }, m.utcOffset = function () { - return 15 * -Math.round(this.$d.getTimezoneOffset() / 15); - }, m.diff = function (r, d, l) { - var $, - y = O.p(d), - M = w(r), - m = (M.utcOffset() - this.utcOffset()) * e, - v = this - M, - g = O.m(this, M); - return g = ($ = {}, $[c] = g / 12, $[f] = g, $[h] = g / 3, $[o] = (v - m) / 6048e5, $[a] = (v - m) / 864e5, $[u] = v / n, $[s] = v / e, $[i] = v / t, $)[y] || v, l ? g : O.a(g); - }, m.daysInMonth = function () { - return this.endOf(f).$D; - }, m.$locale = function () { - return D[this.$L]; - }, m.locale = function (t, e) { - if (!t) return this.$L; - var n = this.clone(), - r = S(t, e, !0); - return r && (n.$L = r), n; - }, m.clone = function () { - return O.w(this.$d, this); - }, m.toDate = function () { - return new Date(this.valueOf()); - }, m.toJSON = function () { - return this.isValid() ? this.toISOString() : null; - }, m.toISOString = function () { - return this.$d.toISOString(); - }, m.toString = function () { - return this.$d.toUTCString(); - }, M; - }(), - T = _.prototype; - return w.prototype = T, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", f], ["$y", c], ["$D", d]].forEach(function (t) { - T[t[1]] = function (e) { - return this.$g(e, t[0], t[1]); - }; - }), w.extend = function (t, e) { - return t.$i || (t(e, _, w), t.$i = !0), w; - }, w.locale = S, w.isDayjs = p, w.unix = function (t) { - return w(1e3 * t); - }, w.en = D[g], w.Ls = D, w.p = {}, w; -}); - -/***/ }), - -/***/ "./node_modules/dayjs/plugin/quarterOfYear.js": -/***/ (function(module) { - -!function (t, n) { - true ? module.exports = n() : 0; -}(this, function () { - "use strict"; - - var t = "month", - n = "quarter"; - return function (e, i) { - var r = i.prototype; - r.quarter = function (t) { - return this.$utils().u(t) ? Math.ceil((this.month() + 1) / 3) : this.month(this.month() % 3 + 3 * (t - 1)); - }; - var s = r.add; - r.add = function (e, i) { - return e = Number(e), this.$utils().p(i) === n ? this.add(3 * e, t) : s.bind(this)(e, i); - }; - var u = r.startOf; - r.startOf = function (e, i) { - var r = this.$utils(), - s = !!r.u(i) || i; - if (r.p(e) === n) { - var o = this.quarter() - 1; - return s ? this.month(3 * o).startOf(t).startOf("day") : this.month(3 * o + 2).endOf(t).endOf("day"); - } - return u.bind(this)(e, i); - }; - }; -}); - -/***/ }), - -/***/ "./node_modules/css-loader/dist/cjs.js!./src/search.css": -/***/ ((module, __webpack_exports__, __webpack_require__) => { - -"use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ A: () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); @@ -541,12 +185,11 @@ ___CSS_LOADER_EXPORT___.push([module.id, `.tapi-search-autocomplete { /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___); -/***/ }), +/***/ }, -/***/ "./node_modules/css-loader/dist/cjs.js!./src/status.css": -/***/ ((module, __webpack_exports__, __webpack_require__) => { +/***/ "./node_modules/css-loader/dist/cjs.js!./src/status.css" +(module, __webpack_exports__, __webpack_require__) { -"use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ A: () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); @@ -583,12 +226,11 @@ ___CSS_LOADER_EXPORT___.push([module.id, `.tapi-dropdown { /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___); -/***/ }), +/***/ }, -/***/ "./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js": -/***/ ((module) => { +/***/ "./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js" +(module) { -"use strict"; var stylesInDOM = []; @@ -674,12 +316,11 @@ module.exports = function (list, options) { }; }; -/***/ }), +/***/ }, -/***/ "./node_modules/style-loader/dist/runtime/insertBySelector.js": -/***/ ((module) => { +/***/ "./node_modules/style-loader/dist/runtime/insertBySelector.js" +(module) { -"use strict"; var memo = {}; @@ -715,12 +356,11 @@ function insertBySelector(insert, style) { } module.exports = insertBySelector; -/***/ }), +/***/ }, -/***/ "./node_modules/style-loader/dist/runtime/insertStyleElement.js": -/***/ ((module) => { +/***/ "./node_modules/style-loader/dist/runtime/insertStyleElement.js" +(module) { -"use strict"; /* istanbul ignore next */ @@ -732,12 +372,11 @@ function insertStyleElement(options) { } module.exports = insertStyleElement; -/***/ }), +/***/ }, -/***/ "./node_modules/style-loader/dist/runtime/setAttributesWithoutAttributes.js": -/***/ ((module, __unused_webpack_exports, __webpack_require__) => { +/***/ "./node_modules/style-loader/dist/runtime/setAttributesWithoutAttributes.js" +(module, __unused_webpack_exports, __webpack_require__) { -"use strict"; /* istanbul ignore next */ @@ -749,12 +388,11 @@ function setAttributesWithoutAttributes(styleElement) { } module.exports = setAttributesWithoutAttributes; -/***/ }), +/***/ }, -/***/ "./node_modules/style-loader/dist/runtime/styleDomAPI.js": -/***/ ((module) => { +/***/ "./node_modules/style-loader/dist/runtime/styleDomAPI.js" +(module) { -"use strict"; /* istanbul ignore next */ @@ -817,12 +455,11 @@ function domAPI(options) { } module.exports = domAPI; -/***/ }), +/***/ }, -/***/ "./node_modules/style-loader/dist/runtime/styleTagTransform.js": -/***/ ((module) => { +/***/ "./node_modules/style-loader/dist/runtime/styleTagTransform.js" +(module) { -"use strict"; /* istanbul ignore next */ @@ -838,7 +475,7 @@ function styleTagTransform(css, styleElement) { } module.exports = styleTagTransform; -/***/ }) +/***/ } /******/ }); /************************************************************************/ @@ -860,7 +497,7 @@ module.exports = styleTagTransform; /******/ }; /******/ /******/ // Execute the module function -/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; @@ -903,20 +540,13 @@ module.exports = styleTagTransform; /******/ /************************************************************************/ var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be in strict mode. -(() => { -"use strict"; -// EXTERNAL MODULE: ./node_modules/dayjs/plugin/quarterOfYear.js -var quarterOfYear = __webpack_require__("./node_modules/dayjs/plugin/quarterOfYear.js"); -// EXTERNAL MODULE: ./node_modules/dayjs/dayjs.min.js -var dayjs_min = __webpack_require__("./node_modules/dayjs/dayjs.min.js"); ;// ./node_modules/chrono-node/dist/esm/types.js -var types_Meridiem; +var Meridiem; (function (Meridiem) { Meridiem[Meridiem["AM"] = 0] = "AM"; Meridiem[Meridiem["PM"] = 1] = "PM"; -})(types_Meridiem || (types_Meridiem = {})); +})(Meridiem || (Meridiem = {})); var Weekday; (function (Weekday) { Weekday[Weekday["SUNDAY"] = 0] = "SUNDAY"; @@ -942,48 +572,34 @@ var Month; Month[Month["NOVEMBER"] = 11] = "NOVEMBER"; Month[Month["DECEMBER"] = 12] = "DECEMBER"; })(Month || (Month = {})); -;// ./node_modules/chrono-node/dist/esm/utils/dayjs.js +;// ./node_modules/chrono-node/dist/esm/utils/dates.js -function assignTheNextDay(component, targetDayJs) { - targetDayJs = targetDayJs.add(1, "day"); - dayjs_assignSimilarDate(component, targetDayJs); - implySimilarTime(component, targetDayJs); +function assignSimilarDate(component, target) { + component.assign("day", target.getDate()); + component.assign("month", target.getMonth() + 1); + component.assign("year", target.getFullYear()); } -function implyTheNextDay(component, targetDayJs) { - targetDayJs = targetDayJs.add(1, "day"); - implySimilarDate(component, targetDayJs); - implySimilarTime(component, targetDayJs); +function assignSimilarTime(component, target) { + component.assign("hour", target.getHours()); + component.assign("minute", target.getMinutes()); + component.assign("second", target.getSeconds()); + component.assign("millisecond", target.getMilliseconds()); + component.assign("meridiem", target.getHours() < 12 ? Meridiem.AM : Meridiem.PM); } -function dayjs_assignSimilarDate(component, targetDayJs) { - component.assign("day", targetDayJs.date()); - component.assign("month", targetDayJs.month() + 1); - component.assign("year", targetDayJs.year()); +function implySimilarDate(component, target) { + component.imply("day", target.getDate()); + component.imply("month", target.getMonth() + 1); + component.imply("year", target.getFullYear()); } -function assignSimilarTime(component, targetDayJs) { - component.assign("hour", targetDayJs.hour()); - component.assign("minute", targetDayJs.minute()); - component.assign("second", targetDayJs.second()); - component.assign("millisecond", targetDayJs.millisecond()); - if (component.get("hour") < 12) { - component.assign("meridiem", types_Meridiem.AM); - } else { - component.assign("meridiem", types_Meridiem.PM); - } -} -function implySimilarDate(component, targetDayJs) { - component.imply("day", targetDayJs.date()); - component.imply("month", targetDayJs.month() + 1); - component.imply("year", targetDayJs.year()); -} -function implySimilarTime(component, targetDayJs) { - component.imply("hour", targetDayJs.hour()); - component.imply("minute", targetDayJs.minute()); - component.imply("second", targetDayJs.second()); - component.imply("millisecond", targetDayJs.millisecond()); +function implySimilarTime(component, target) { + component.imply("hour", target.getHours()); + component.imply("minute", target.getMinutes()); + component.imply("second", target.getSeconds()); + component.imply("millisecond", target.getMilliseconds()); + component.imply("meridiem", target.getHours() < 12 ? Meridiem.AM : Meridiem.PM); } ;// ./node_modules/chrono-node/dist/esm/timezone.js - const TIMEZONE_ABBR_MAP = { ACDT: 630, ACST: 570, @@ -1240,29 +856,163 @@ function toTimezoneOffset(timezoneInput, date, timezoneOverrides = {}) { if (date == null) { return null; } - if (dayjs_min(date).isAfter(matchedTimezone.dstStart(date.getFullYear())) && !dayjs_min(date).isAfter(matchedTimezone.dstEnd(date.getFullYear()))) { + if (date > matchedTimezone.dstStart(date.getFullYear()) && !(date > matchedTimezone.dstEnd(date.getFullYear()))) { return matchedTimezone.timezoneOffsetDuringDst; } return matchedTimezone.timezoneOffsetNonDst; } +;// ./node_modules/chrono-node/dist/esm/calculation/duration.js +const EmptyDuration = { + day: 0, + second: 0, + millisecond: 0 +}; +function addDuration(ref, duration) { + let date = new Date(ref); + if (duration["y"]) { + duration["year"] = duration["y"]; + delete duration["y"]; + } + if (duration["mo"]) { + duration["month"] = duration["mo"]; + delete duration["mo"]; + } + if (duration["M"]) { + duration["month"] = duration["M"]; + delete duration["M"]; + } + if (duration["w"]) { + duration["week"] = duration["w"]; + delete duration["w"]; + } + if (duration["d"]) { + duration["day"] = duration["d"]; + delete duration["d"]; + } + if (duration["h"]) { + duration["hour"] = duration["h"]; + delete duration["h"]; + } + if (duration["m"]) { + duration["minute"] = duration["m"]; + delete duration["m"]; + } + if (duration["s"]) { + duration["second"] = duration["s"]; + delete duration["s"]; + } + if (duration["ms"]) { + duration["millisecond"] = duration["ms"]; + delete duration["ms"]; + } + if ("year" in duration) { + const floor = Math.floor(duration["year"]); + date.setFullYear(date.getFullYear() + floor); + const remainingFraction = duration["year"] - floor; + if (remainingFraction > 0) { + duration.month = duration?.month ?? 0; + duration.month += remainingFraction * 12; + } + } + if ("quarter" in duration) { + const floor = Math.floor(duration["quarter"]); + date.setMonth(date.getMonth() + floor * 3); + } + if ("month" in duration) { + const floor = Math.floor(duration["month"]); + date.setMonth(date.getMonth() + floor); + const remainingFraction = duration["month"] - floor; + if (remainingFraction > 0) { + duration.week = duration?.week ?? 0; + duration.week += remainingFraction * 4; + } + } + if ("week" in duration) { + const floor = Math.floor(duration["week"]); + date.setDate(date.getDate() + floor * 7); + const remainingFraction = duration["week"] - floor; + if (remainingFraction > 0) { + duration.day = duration?.day ?? 0; + duration.day += Math.round(remainingFraction * 7); + } + } + if ("day" in duration) { + const floor = Math.floor(duration["day"]); + date.setDate(date.getDate() + floor); + const remainingFraction = duration["day"] - floor; + if (remainingFraction > 0) { + duration.hour = duration?.hour ?? 0; + duration.hour += Math.round(remainingFraction * 24); + } + } + if ("hour" in duration) { + const floor = Math.floor(duration["hour"]); + date.setHours(date.getHours() + floor); + const remainingFraction = duration["hour"] - floor; + if (remainingFraction > 0) { + duration.minute = duration?.minute ?? 0; + duration.minute += Math.round(remainingFraction * 60); + } + } + if ("minute" in duration) { + const floor = Math.floor(duration["minute"]); + date.setMinutes(date.getMinutes() + floor); + const remainingFraction = duration["minute"] - floor; + if (remainingFraction > 0) { + duration.second = duration?.second ?? 0; + duration.second += Math.round(remainingFraction * 60); + } + } + if ("second" in duration) { + const floor = Math.floor(duration["second"]); + date.setSeconds(date.getSeconds() + floor); + const remainingFraction = duration["second"] - floor; + if (remainingFraction > 0) { + duration.millisecond = duration?.millisecond ?? 0; + duration.millisecond += Math.round(remainingFraction * 1000); + } + } + if ("millisecond" in duration) { + const floor = Math.floor(duration["millisecond"]); + date.setMilliseconds(date.getMilliseconds() + floor); + } + return date; +} +function reverseDuration(duration) { + const reversed = {}; + for (const key in duration) { + reversed[key] = -duration[key]; + } + return reversed; +} ;// ./node_modules/chrono-node/dist/esm/results.js - -dayjs_min.extend(quarterOfYear); class ReferenceWithTimezone { - constructor(input) { - input = input ?? new Date(); + instant; + timezoneOffset; + constructor(instant, timezoneOffset) { + this.instant = instant ?? new Date(); + this.timezoneOffset = timezoneOffset ?? null; + } + static fromDate(date) { + return new ReferenceWithTimezone(date); + } + static fromInput(input, timezoneOverrides) { if (input instanceof Date) { - this.instant = input; - } else { - this.instant = input.instant ?? new Date(); - this.timezoneOffset = toTimezoneOffset(input.timezone, this.instant); + return ReferenceWithTimezone.fromDate(input); } + const instant = input?.instant ?? new Date(); + const timezoneOffset = toTimezoneOffset(input?.timezone, instant, timezoneOverrides); + return new ReferenceWithTimezone(instant, timezoneOffset); } getDateWithAdjustedTimezone() { - return new Date(this.instant.getTime() + this.getSystemTimezoneAdjustmentMinute(this.instant) * 60000); + const date = new Date(this.instant); + if (this.timezoneOffset !== null) { + date.setMinutes(date.getMinutes() - this.getSystemTimezoneAdjustmentMinute(this.instant)); + } + return date; } getSystemTimezoneAdjustmentMinute(date, overrideTimezoneOffset) { if (!date || date.getTime() < 0) { @@ -1272,10 +1022,16 @@ class ReferenceWithTimezone { const targetTimezoneOffset = overrideTimezoneOffset ?? this.timezoneOffset ?? currentTimezoneOffset; return currentTimezoneOffset - targetTimezoneOffset; } + getTimezoneOffset() { + return this.timezoneOffset ?? -this.instant.getTimezoneOffset(); + } } -class results_ParsingComponents { +class ParsingComponents { + knownValues; + impliedValues; + reference; + _tags = new Set(); constructor(reference, knownComponents) { - this._tags = new Set(); this.reference = reference; this.knownValues = {}; this.impliedValues = {}; @@ -1284,15 +1040,54 @@ class results_ParsingComponents { this.knownValues[key] = knownComponents[key]; } } - const refDayJs = dayjs_min(reference.instant); - this.imply("day", refDayJs.date()); - this.imply("month", refDayJs.month() + 1); - this.imply("year", refDayJs.year()); + const date = reference.getDateWithAdjustedTimezone(); + this.imply("day", date.getDate()); + this.imply("month", date.getMonth() + 1); + this.imply("year", date.getFullYear()); this.imply("hour", 12); this.imply("minute", 0); this.imply("second", 0); this.imply("millisecond", 0); } + static createRelativeFromReference(reference, duration = EmptyDuration) { + let date = addDuration(reference.getDateWithAdjustedTimezone(), duration); + const components = new ParsingComponents(reference); + components.addTag("result/relativeDate"); + if ("hour" in duration || "minute" in duration || "second" in duration || "millisecond" in duration) { + components.addTag("result/relativeDateAndTime"); + assignSimilarTime(components, date); + assignSimilarDate(components, date); + components.assign("timezoneOffset", reference.getTimezoneOffset()); + } else { + implySimilarTime(components, date); + components.imply("timezoneOffset", reference.getTimezoneOffset()); + if ("day" in duration) { + components.assign("day", date.getDate()); + components.assign("month", date.getMonth() + 1); + components.assign("year", date.getFullYear()); + components.assign("weekday", date.getDay()); + } else if ("week" in duration) { + components.assign("day", date.getDate()); + components.assign("month", date.getMonth() + 1); + components.assign("year", date.getFullYear()); + components.imply("weekday", date.getDay()); + } else { + components.imply("day", date.getDate()); + if ("month" in duration) { + components.assign("month", date.getMonth() + 1); + components.assign("year", date.getFullYear()); + } else { + components.imply("month", date.getMonth() + 1); + if ("year" in duration) { + components.assign("year", date.getFullYear()); + } else { + components.imply("year", date.getFullYear()); + } + } + } + } + return components; + } get(component) { if (component in this.knownValues) { return this.knownValues[component]; @@ -1320,12 +1115,35 @@ class results_ParsingComponents { delete this.impliedValues[component]; return this; } - delete(component) { - delete this.knownValues[component]; - delete this.impliedValues[component]; + addDurationAsImplied(duration) { + const currentDate = this.dateWithoutTimezoneAdjustment(); + const date = addDuration(currentDate, duration); + if ("day" in duration || "week" in duration || "month" in duration || "year" in duration) { + this.delete(["day", "weekday", "month", "year"]); + this.imply("day", date.getDate()); + this.imply("weekday", date.getDay()); + this.imply("month", date.getMonth() + 1); + this.imply("year", date.getFullYear()); + } + if ("second" in duration || "minute" in duration || "hour" in duration) { + this.delete(["second", "minute", "hour"]); + this.imply("second", date.getSeconds()); + this.imply("minute", date.getMinutes()); + this.imply("hour", date.getHours()); + } + return this; + } + delete(components) { + if (typeof components === "string") { + components = [components]; + } + for (const component of components) { + delete this.knownValues[component]; + delete this.impliedValues[component]; + } } clone() { - const component = new results_ParsingComponents(this.reference); + const component = new ParsingComponents(this.reference); component.knownValues = {}; component.impliedValues = {}; for (const key in this.knownValues) { @@ -1364,9 +1182,6 @@ class results_ParsingComponents { impliedValues: ${JSON.stringify(this.impliedValues)}}, reference: ${JSON.stringify(this.reference)}]`; } - dayjs() { - return dayjs_min(this.date()); - } date() { const date = this.dateWithoutTimezoneAdjustment(); const timezoneAdjustment = this.reference.getSystemTimezoneAdjustmentMinute(date, this.get("timezoneOffset")); @@ -1390,57 +1205,20 @@ class results_ParsingComponents { date.setFullYear(this.get("year")); return date; } - static createRelativeFromReference(reference, fragments) { - let date = dayjs_min(reference.instant); - for (const key in fragments) { - date = date.add(fragments[key], key); - } - const components = new results_ParsingComponents(reference); - if (fragments["hour"] || fragments["minute"] || fragments["second"]) { - assignSimilarTime(components, date); - dayjs_assignSimilarDate(components, date); - if (reference.timezoneOffset !== null) { - components.assign("timezoneOffset", -reference.instant.getTimezoneOffset()); - } - } else { - implySimilarTime(components, date); - if (reference.timezoneOffset !== null) { - components.imply("timezoneOffset", -reference.instant.getTimezoneOffset()); - } - if (fragments["d"]) { - components.assign("day", date.date()); - components.assign("month", date.month() + 1); - components.assign("year", date.year()); - } else if (fragments["week"]) { - components.assign("day", date.date()); - components.assign("month", date.month() + 1); - components.assign("year", date.year()); - components.imply("weekday", date.day()); - } else { - components.imply("day", date.date()); - if (fragments["month"]) { - components.assign("month", date.month() + 1); - components.assign("year", date.year()); - } else { - components.imply("month", date.month() + 1); - if (fragments["year"]) { - components.assign("year", date.year()); - } else { - components.imply("year", date.year()); - } - } - } - } - return components; - } } class ParsingResult { + refDate; + index; + text; + reference; + start; + end; constructor(reference, index, text, start, end) { this.reference = reference; this.refDate = reference.instant; this.index = index; this.text = text; - this.start = start || new results_ParsingComponents(reference); + this.start = start || new ParsingComponents(reference); this.end = end; } clone() { @@ -1452,6 +1230,20 @@ class ParsingResult { date() { return this.start.date(); } + addTag(tag) { + this.start.addTag(tag); + if (this.end) { + this.end.addTag(tag); + } + return this; + } + addTags(tags) { + this.start.addTags(tags); + if (this.end) { + this.end.addTags(tags); + } + return this; + } tags() { const combinedTags = new Set(this.start.tags()); if (this.end) { @@ -1499,19 +1291,21 @@ function findMostLikelyADYear(yearNumber) { return yearNumber; } function findYearClosestToRef(refDate, day, month) { - const refMoment = dayjs_min(refDate); - let dateMoment = refMoment; - dateMoment = dateMoment.month(month - 1); - dateMoment = dateMoment.date(day); - dateMoment = dateMoment.year(refMoment.year()); - const nextYear = dateMoment.add(1, "y"); - const lastYear = dateMoment.add(-1, "y"); - if (Math.abs(nextYear.diff(refMoment)) < Math.abs(dateMoment.diff(refMoment))) { - dateMoment = nextYear; - } else if (Math.abs(lastYear.diff(refMoment)) < Math.abs(dateMoment.diff(refMoment))) { - dateMoment = lastYear; + let date = new Date(refDate); + date.setMonth(month - 1); + date.setDate(day); + const nextYear = addDuration(date, { + "year": 1 + }); + const lastYear = addDuration(date, { + "year": -1 + }); + if (Math.abs(nextYear.getTime() - refDate.getTime()) < Math.abs(date.getTime() - refDate.getTime())) { + date = nextYear; + } else if (Math.abs(lastYear.getTime() - refDate.getTime()) < Math.abs(date.getTime() - refDate.getTime())) { + date = lastYear; } - return dateMoment.year(); + return date.getFullYear(); } ;// ./node_modules/chrono-node/dist/esm/locales/en/constants.js @@ -1648,8 +1442,8 @@ const TIME_UNIT_DICTIONARY_NO_ABBR = { minutes: "minute", hour: "hour", hours: "hour", - day: "d", - days: "d", + day: "day", + days: "day", week: "week", weeks: "week", month: "month", @@ -1674,10 +1468,10 @@ const TIME_UNIT_DICTIONARY = { hrs: "hour", hour: "hour", hours: "hour", - d: "d", - day: "d", - days: "d", - w: "w", + d: "day", + day: "day", + days: "day", + w: "week", week: "week", weeks: "week", mo: "month", @@ -1744,7 +1538,7 @@ const SINGLE_TIME_UNIT_NO_ABBR_PATTERN = `(${NUMBER_PATTERN})\\s{0,3}(${matchAny const TIME_UNIT_CONNECTOR_PATTERN = `\\s{0,5},?(?:\\s*and)?\\s{0,5}`; const TIME_UNITS_PATTERN = repeatedTimeunitPattern(`(?:(?:about|around)\\s{0,3})?`, SINGLE_TIME_UNIT_PATTERN, TIME_UNIT_CONNECTOR_PATTERN); const TIME_UNITS_NO_ABBR_PATTERN = repeatedTimeunitPattern(`(?:(?:about|around)\\s{0,3})?`, SINGLE_TIME_UNIT_NO_ABBR_PATTERN, TIME_UNIT_CONNECTOR_PATTERN); -function parseTimeUnits(timeunitText) { +function parseDuration(timeunitText) { const fragments = {}; let remainingText = timeunitText; let match = SINGLE_TIME_UNIT_REGEX.exec(remainingText); @@ -1768,16 +1562,14 @@ function collectDateTimeFragment(fragments, match) { } ;// ./node_modules/chrono-node/dist/esm/common/parsers/AbstractParserWithWordBoundary.js class AbstractParserWithWordBoundaryChecking { - constructor() { - this.cachedInnerPattern = null; - this.cachedPattern = null; - } innerPatternHasChange(context, currentInnerPattern) { return this.innerPattern(context) !== currentInnerPattern; } patternLeftBoundary() { return `(\\W|^)`; } + cachedInnerPattern = null; + cachedPattern = null; pattern(context) { if (this.cachedInnerPattern) { if (!this.innerPatternHasChange(context, this.cachedInnerPattern)) { @@ -1806,6 +1598,7 @@ const PATTERN_WITH_OPTIONAL_PREFIX = new RegExp(`(?:(?:within|in|for)\\s*)?` + ` const PATTERN_WITH_PREFIX = new RegExp(`(?:within|in|for)\\s*` + `(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?(${TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); const PATTERN_WITH_PREFIX_STRICT = new RegExp(`(?:within|in|for)\\s*` + `(?:(?:about|around|roughly|approximately|just)\\s*(?:~\\s*)?)?(${TIME_UNITS_NO_ABBR_PATTERN})(?=\\W|$)`, "i"); class ENTimeUnitWithinFormatParser extends AbstractParserWithWordBoundaryChecking { + strictMode; constructor(strictMode) { super(); this.strictMode = strictMode; @@ -1820,11 +1613,11 @@ class ENTimeUnitWithinFormatParser extends AbstractParserWithWordBoundaryCheckin if (match[0].match(/^for\s*the\s*\w+/)) { return null; } - const timeUnits = parseTimeUnits(match[1]); + const timeUnits = parseDuration(match[1]); if (!timeUnits) { return null; } - return results_ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + return ParsingComponents.createRelativeFromReference(context.reference, timeUnits); } } ;// ./node_modules/chrono-node/dist/esm/locales/en/parsers/ENMonthNameLittleEndianParser.js @@ -1881,6 +1674,7 @@ const ENMonthNameMiddleEndianParser_DATE_GROUP = 2; const ENMonthNameMiddleEndianParser_DATE_TO_GROUP = 3; const ENMonthNameMiddleEndianParser_YEAR_GROUP = 4; class ENMonthNameMiddleEndianParser extends AbstractParserWithWordBoundaryChecking { + shouldSkipYearLikeDate; constructor(shouldSkipYearLikeDate) { super(); this.shouldSkipYearLikeDate = shouldSkipYearLikeDate; @@ -1927,7 +1721,7 @@ class ENMonthNameMiddleEndianParser extends AbstractParserWithWordBoundaryChecki -const ENMonthNameParser_PATTERN = new RegExp(`((?:in)\\s*)?` + `(${matchAnyPattern(MONTH_DICTIONARY)})` + `\\s*` + `(?:` + `[,-]?\\s*(${YEAR_PATTERN})?` + ")?" + "(?=[^\\s\\w]|\\s+[^0-9]|\\s+$|$)", "i"); +const ENMonthNameParser_PATTERN = new RegExp(`((?:in)\\s*)?` + `(${matchAnyPattern(MONTH_DICTIONARY)})` + `\\s*` + `(?:` + `(?:,|-|of)?\\s*(${YEAR_PATTERN})?` + ")?" + "(?=[^\\s\\w]|\\s+[^0-9]|\\s+$|$)", "i"); const PREFIX_GROUP = 1; const ENMonthNameParser_MONTH_NAME_GROUP = 2; const ENMonthNameParser_YEAR_GROUP = 3; @@ -1965,6 +1759,7 @@ const ENYearMonthDayParser_MONTH_NAME_GROUP = 2; const MONTH_NUMBER_GROUP = 3; const DATE_NUMBER_GROUP = 4; class ENYearMonthDayParser extends AbstractParserWithWordBoundaryChecking { + strictMonthDateOrder; constructor(strictMonthDateOrder) { super(); this.strictMonthDateOrder = strictMonthDateOrder; @@ -2023,13 +1818,8 @@ const SECOND_GROUP = 4; const MILLI_SECOND_GROUP = 5; const AM_PM_HOUR_GROUP = 6; class AbstractTimeExpressionParser { + strictMode; constructor(strictMode = false) { - this.cachedPrimaryPrefix = null; - this.cachedPrimarySuffix = null; - this.cachedPrimaryTimePattern = null; - this.cachedFollowingPhase = null; - this.cachedFollowingSuffix = null; - this.cachedFollowingTimePatten = null; this.strictMode = strictMode; } patternFlags() { @@ -2087,6 +1877,9 @@ class AbstractTimeExpressionParser { let meridiem = null; let hour = parseInt(match[HOUR_GROUP]); if (hour > 100) { + if (match[HOUR_GROUP].length == 4 && match[MINUTE_GROUP] == null && !match[AM_PM_HOUR_GROUP]) { + return null; + } if (this.strictMode || match[MINUTE_GROUP] != null) { return null; } @@ -2106,19 +1899,19 @@ class AbstractTimeExpressionParser { return null; } if (hour > 12) { - meridiem = types_Meridiem.PM; + meridiem = Meridiem.PM; } if (match[AM_PM_HOUR_GROUP] != null) { if (hour > 12) return null; const ampm = match[AM_PM_HOUR_GROUP][0].toLowerCase(); if (ampm == "a") { - meridiem = types_Meridiem.AM; + meridiem = Meridiem.AM; if (hour == 12) { hour = 0; } } if (ampm == "p") { - meridiem = types_Meridiem.PM; + meridiem = Meridiem.PM; if (hour != 12) { hour += 12; } @@ -2130,9 +1923,9 @@ class AbstractTimeExpressionParser { components.assign("meridiem", meridiem); } else { if (hour < 12) { - components.imply("meridiem", types_Meridiem.AM); + components.imply("meridiem", Meridiem.AM); } else { - components.imply("meridiem", types_Meridiem.PM); + components.imply("meridiem", Meridiem.PM); } } if (match[MILLI_SECOND_GROUP] != null) { @@ -2172,7 +1965,7 @@ class AbstractTimeExpressionParser { return null; } if (hour >= 12) { - meridiem = types_Meridiem.PM; + meridiem = Meridiem.PM; } if (match[AM_PM_HOUR_GROUP] != null) { if (hour > 12) { @@ -2180,7 +1973,7 @@ class AbstractTimeExpressionParser { } const ampm = match[AM_PM_HOUR_GROUP][0].toLowerCase(); if (ampm == "a") { - meridiem = types_Meridiem.AM; + meridiem = Meridiem.AM; if (hour == 12) { hour = 0; if (!components.isCertain("day")) { @@ -2189,17 +1982,17 @@ class AbstractTimeExpressionParser { } } if (ampm == "p") { - meridiem = types_Meridiem.PM; + meridiem = Meridiem.PM; if (hour != 12) hour += 12; } if (!result.start.isCertain("meridiem")) { - if (meridiem == types_Meridiem.AM) { - result.start.imply("meridiem", types_Meridiem.AM); + if (meridiem == Meridiem.AM) { + result.start.imply("meridiem", Meridiem.AM); if (result.start.get("hour") == 12) { result.start.assign("hour", 0); } } else { - result.start.imply("meridiem", types_Meridiem.PM); + result.start.imply("meridiem", Meridiem.PM); if (result.start.get("hour") != 12) { result.start.assign("hour", result.start.get("hour") + 12); } @@ -2214,15 +2007,15 @@ class AbstractTimeExpressionParser { const startAtPM = result.start.isCertain("meridiem") && result.start.get("hour") > 12; if (startAtPM) { if (result.start.get("hour") - 12 > hour) { - components.imply("meridiem", types_Meridiem.AM); + components.imply("meridiem", Meridiem.AM); } else if (hour <= 12) { components.assign("hour", hour + 12); - components.assign("meridiem", types_Meridiem.PM); + components.assign("meridiem", Meridiem.PM); } } else if (hour > 12) { - components.imply("meridiem", types_Meridiem.PM); + components.imply("meridiem", Meridiem.PM); } else if (hour <= 12) { - components.imply("meridiem", types_Meridiem.AM); + components.imply("meridiem", Meridiem.AM); } } if (components.date().getTime() < result.start.date().getTime()) { @@ -2278,6 +2071,9 @@ class AbstractTimeExpressionParser { } return result; } + cachedPrimaryPrefix = null; + cachedPrimarySuffix = null; + cachedPrimaryTimePattern = null; getPrimaryTimePatternThroughCache() { const primaryPrefix = this.primaryPrefix(); const primarySuffix = this.primarySuffix(); @@ -2289,6 +2085,9 @@ class AbstractTimeExpressionParser { this.cachedPrimarySuffix = primarySuffix; return this.cachedPrimaryTimePattern; } + cachedFollowingPhase = null; + cachedFollowingSuffix = null; + cachedFollowingTimePatten = null; getFollowingTimePatternThroughCache() { const followingPhase = this.followingPhase(); const followingSuffix = this.followingSuffix(); @@ -2326,20 +2125,20 @@ class ENTimeExpressionParser extends AbstractTimeExpressionParser { const hour = components.get("hour"); if (hour >= 6 && hour < 12) { components.assign("hour", components.get("hour") + 12); - components.assign("meridiem", types_Meridiem.PM); + components.assign("meridiem", Meridiem.PM); } else if (hour < 6) { - components.assign("meridiem", types_Meridiem.AM); + components.assign("meridiem", Meridiem.AM); } } if (match[0].endsWith("afternoon")) { - components.assign("meridiem", types_Meridiem.PM); + components.assign("meridiem", Meridiem.PM); const hour = components.get("hour"); if (hour >= 0 && hour <= 6) { components.assign("hour", components.get("hour") + 12); } } if (match[0].endsWith("morning")) { - components.assign("meridiem", types_Meridiem.AM); + components.assign("meridiem", Meridiem.AM); const hour = components.get("hour"); if (hour < 12) { components.assign("hour", components.get("hour")); @@ -2347,32 +2146,13 @@ class ENTimeExpressionParser extends AbstractTimeExpressionParser { } return components.addTag("parser/ENTimeExpressionParser"); } -} -;// ./node_modules/chrono-node/dist/esm/utils/timeunits.js -function reverseTimeUnits(timeUnits) { - const reversed = {}; - for (const key in timeUnits) { - reversed[key] = -timeUnits[key]; + extractFollowingTimeComponents(context, match, result) { + const followingComponents = super.extractFollowingTimeComponents(context, match, result); + if (followingComponents) { + followingComponents.addTag("parser/ENTimeExpressionParser"); + } + return followingComponents; } - return reversed; -} -function addImpliedTimeUnits(components, timeUnits) { - const output = components.clone(); - let date = components.dayjs(); - for (const key in timeUnits) { - date = date.add(timeUnits[key], key); - } - if ("day" in timeUnits || "d" in timeUnits || "week" in timeUnits || "month" in timeUnits || "year" in timeUnits) { - output.imply("day", date.date()); - output.imply("month", date.month() + 1); - output.imply("year", date.year()); - } - if ("second" in timeUnits || "minute" in timeUnits || "hour" in timeUnits) { - output.imply("second", date.second()); - output.imply("minute", date.minute()); - output.imply("hour", date.hour()); - } - return output; } ;// ./node_modules/chrono-node/dist/esm/locales/en/parsers/ENTimeUnitAgoFormatParser.js @@ -2382,6 +2162,7 @@ function addImpliedTimeUnits(components, timeUnits) { const ENTimeUnitAgoFormatParser_PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}(?:ago|before|earlier)(?=\\W|$)`, "i"); const STRICT_PATTERN = new RegExp(`(${TIME_UNITS_NO_ABBR_PATTERN})\\s{0,5}(?:ago|before|earlier)(?=\\W|$)`, "i"); class ENTimeUnitAgoFormatParser extends AbstractParserWithWordBoundaryChecking { + strictMode; constructor(strictMode) { super(); this.strictMode = strictMode; @@ -2390,12 +2171,11 @@ class ENTimeUnitAgoFormatParser extends AbstractParserWithWordBoundaryChecking { return this.strictMode ? STRICT_PATTERN : ENTimeUnitAgoFormatParser_PATTERN; } innerExtract(context, match) { - const timeUnits = parseTimeUnits(match[1]); - if (!timeUnits) { + const duration = parseDuration(match[1]); + if (!duration) { return null; } - const outputTimeUnits = reverseTimeUnits(timeUnits); - return results_ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits); + return ParsingComponents.createRelativeFromReference(context.reference, reverseDuration(duration)); } } ;// ./node_modules/chrono-node/dist/esm/locales/en/parsers/ENTimeUnitLaterFormatParser.js @@ -2406,6 +2186,7 @@ const ENTimeUnitLaterFormatParser_PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\ const ENTimeUnitLaterFormatParser_STRICT_PATTERN = new RegExp(`(${TIME_UNITS_NO_ABBR_PATTERN})\\s{0,5}(later|after|from now)(?=\\W|$)`, "i"); const GROUP_NUM_TIMEUNITS = 1; class ENTimeUnitLaterFormatParser extends AbstractParserWithWordBoundaryChecking { + strictMode; constructor(strictMode) { super(); this.strictMode = strictMode; @@ -2414,11 +2195,11 @@ class ENTimeUnitLaterFormatParser extends AbstractParserWithWordBoundaryChecking return this.strictMode ? ENTimeUnitLaterFormatParser_STRICT_PATTERN : ENTimeUnitLaterFormatParser_PATTERN; } innerExtract(context, match) { - const timeUnits = parseTimeUnits(match[GROUP_NUM_TIMEUNITS]); + const timeUnits = parseDuration(match[GROUP_NUM_TIMEUNITS]); if (!timeUnits) { return null; } - return results_ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + return ParsingComponents.createRelativeFromReference(context.reference, timeUnits); } } ;// ./node_modules/chrono-node/dist/esm/common/abstractRefiners.js @@ -2459,6 +2240,7 @@ class MergingRefiner { } ;// ./node_modules/chrono-node/dist/esm/common/refiners/AbstractMergeDateRangeRefiner.js + class AbstractMergeDateRangeRefiner extends MergingRefiner { shouldMergeResults(textBetween, currentResult, nextResult) { return !currentResult.end && !nextResult.end && textBetween.match(this.patternBetween()) != null; @@ -2476,25 +2258,41 @@ class AbstractMergeDateRangeRefiner extends MergingRefiner { } }); } - if (fromResult.start.date().getTime() > toResult.start.date().getTime()) { - let fromMoment = fromResult.start.dayjs(); - let toMoment = toResult.start.dayjs(); - if (toResult.start.isOnlyWeekdayComponent() && toMoment.add(7, "days").isAfter(fromMoment)) { - toMoment = toMoment.add(7, "days"); - toResult.start.imply("day", toMoment.date()); - toResult.start.imply("month", toMoment.month() + 1); - toResult.start.imply("year", toMoment.year()); - } else if (fromResult.start.isOnlyWeekdayComponent() && fromMoment.add(-7, "days").isBefore(toMoment)) { - fromMoment = fromMoment.add(-7, "days"); - fromResult.start.imply("day", fromMoment.date()); - fromResult.start.imply("month", fromMoment.month() + 1); - fromResult.start.imply("year", fromMoment.year()); - } else if (toResult.start.isDateWithUnknownYear() && toMoment.add(1, "years").isAfter(fromMoment)) { - toMoment = toMoment.add(1, "years"); - toResult.start.imply("year", toMoment.year()); - } else if (fromResult.start.isDateWithUnknownYear() && fromMoment.add(-1, "years").isBefore(toMoment)) { - fromMoment = fromMoment.add(-1, "years"); - fromResult.start.imply("year", fromMoment.year()); + if (fromResult.start.date() > toResult.start.date()) { + let fromDate = fromResult.start.date(); + let toDate = toResult.start.date(); + if (toResult.start.isOnlyWeekdayComponent() && addDuration(toDate, { + day: 7 + }) > fromDate) { + toDate = addDuration(toDate, { + day: 7 + }); + toResult.start.imply("day", toDate.getDate()); + toResult.start.imply("month", toDate.getMonth() + 1); + toResult.start.imply("year", toDate.getFullYear()); + } else if (fromResult.start.isOnlyWeekdayComponent() && addDuration(fromDate, { + day: -7 + }) < toDate) { + fromDate = addDuration(fromDate, { + day: -7 + }); + fromResult.start.imply("day", fromDate.getDate()); + fromResult.start.imply("month", fromDate.getMonth() + 1); + fromResult.start.imply("year", fromDate.getFullYear()); + } else if (toResult.start.isDateWithUnknownYear() && addDuration(toDate, { + year: 1 + }) > fromDate) { + toDate = addDuration(toDate, { + year: 1 + }); + toResult.start.imply("year", toDate.getFullYear()); + } else if (fromResult.start.isDateWithUnknownYear() && addDuration(fromDate, { + year: -1 + }) < toDate) { + fromDate = addDuration(fromDate, { + year: -1 + }); + fromResult.start.imply("year", fromDate.getFullYear()); } else { [toResult, fromResult] = [fromResult, toResult]; } @@ -2531,11 +2329,12 @@ function mergeDateTimeResult(dateResult, timeResult) { const endTime = timeResult.end == null ? timeResult.start : timeResult.end; const endDateTime = mergeDateTimeComponent(endDate, endTime); if (dateResult.end == null && endDateTime.date().getTime() < result.start.date().getTime()) { - const nextDayJs = endDateTime.dayjs().add(1, "day"); + const nextDay = new Date(endDateTime.date().getTime()); + nextDay.setDate(nextDay.getDate() + 1); if (endDateTime.isCertain("day")) { - dayjs_assignSimilarDate(endDateTime, nextDayJs); + assignSimilarDate(endDateTime, nextDay); } else { - implySimilarDate(endDateTime, nextDayJs); + implySimilarDate(endDateTime, nextDay); } } result.end = endDateTime; @@ -2572,7 +2371,7 @@ function mergeDateTimeComponent(dateComponent, timeComponent) { } else if (timeComponent.get("meridiem") != null && dateTimeComponent.get("meridiem") == null) { dateTimeComponent.imply("meridiem", timeComponent.get("meridiem")); } - if (dateTimeComponent.get("meridiem") == types_Meridiem.PM && dateTimeComponent.get("hour") < 12) { + if (dateTimeComponent.get("meridiem") == Meridiem.PM && dateTimeComponent.get("hour") < 12) { if (timeComponent.isCertain("hour")) { dateTimeComponent.assign("hour", dateTimeComponent.get("hour") + 12); } else { @@ -2608,6 +2407,7 @@ class ENMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner { const TIMEZONE_NAME_PATTERN = new RegExp("^\\s*,?\\s*\\(?([A-Z]{2,4})\\)?(?=\\W|$)", "i"); class ExtractTimezoneAbbrRefiner { + timezoneOverrides; constructor(timezoneOverrides) { this.timezoneOverrides = timezoneOverrides; } @@ -2732,55 +2532,58 @@ class OverlapRemovalRefiner { ;// ./node_modules/chrono-node/dist/esm/common/refiners/ForwardDateRefiner.js + class ForwardDateRefiner { refine(context, results) { if (!context.option.forwardDate) { return results; } results.forEach(result => { - let refMoment = dayjs_min(context.refDate); - if (result.start.isOnlyTime() && refMoment.isAfter(result.start.dayjs())) { - refMoment = refMoment.add(1, "day"); - implySimilarDate(result.start, refMoment); + let refDate = context.reference.getDateWithAdjustedTimezone(); + if (result.start.isOnlyTime() && context.reference.instant > result.start.date()) { + const refDate = context.reference.getDateWithAdjustedTimezone(); + const refFollowingDay = new Date(refDate); + refFollowingDay.setDate(refFollowingDay.getDate() + 1); + implySimilarDate(result.start, refFollowingDay); + context.debug(() => { + console.log(`${this.constructor.name} adjusted ${result} time from the ref date (${refDate}) to the following day (${refFollowingDay})`); + }); if (result.end && result.end.isOnlyTime()) { - implySimilarDate(result.end, refMoment); - if (result.start.dayjs().isAfter(result.end.dayjs())) { - refMoment = refMoment.add(1, "day"); - implySimilarDate(result.end, refMoment); + implySimilarDate(result.end, refFollowingDay); + if (result.start.date() > result.end.date()) { + refFollowingDay.setDate(refFollowingDay.getDate() + 1); + implySimilarDate(result.end, refFollowingDay); } } - context.debug(() => { - console.log(`${this.constructor.name} adjusted ${result} time result (${result.start})`); - }); } - if (result.start.isOnlyWeekdayComponent() && refMoment.isAfter(result.start.dayjs())) { - if (refMoment.day() >= result.start.get("weekday")) { - refMoment = refMoment.day(result.start.get("weekday") + 7); - } else { - refMoment = refMoment.day(result.start.get("weekday")); + if (result.start.isOnlyWeekdayComponent() && refDate > result.start.date()) { + let daysToAdd = result.start.get("weekday") - refDate.getDay(); + if (daysToAdd <= 0) { + daysToAdd += 7; } - result.start.imply("day", refMoment.date()); - result.start.imply("month", refMoment.month() + 1); - result.start.imply("year", refMoment.year()); + refDate = addDuration(refDate, { + day: daysToAdd + }); + implySimilarDate(result.start, refDate); context.debug(() => { console.log(`${this.constructor.name} adjusted ${result} weekday (${result.start})`); }); if (result.end && result.end.isOnlyWeekdayComponent()) { - if (refMoment.day() > result.end.get("weekday")) { - refMoment = refMoment.day(result.end.get("weekday") + 7); - } else { - refMoment = refMoment.day(result.end.get("weekday")); + let daysToAdd = result.end.get("weekday") - refDate.getDay(); + if (daysToAdd <= 0) { + daysToAdd += 7; } - result.end.imply("day", refMoment.date()); - result.end.imply("month", refMoment.month() + 1); - result.end.imply("year", refMoment.year()); + refDate = addDuration(refDate, { + day: daysToAdd + }); + implySimilarDate(result.end, refDate); context.debug(() => { console.log(`${this.constructor.name} adjusted ${result} weekday (${result.end})`); }); } } - if (result.start.isDateWithUnknownYear() && refMoment.isAfter(result.start.dayjs())) { - for (let i = 0; i < 3 && refMoment.isAfter(result.start.dayjs()); i++) { + if (result.start.isDateWithUnknownYear() && refDate > result.start.date()) { + for (let i = 0; i < 3 && refDate > result.start.date(); i++) { result.start.imply("year", result.start.get("year") + 1); context.debug(() => { console.log(`${this.constructor.name} adjusted ${result} year (${result.start})`); @@ -2800,6 +2603,7 @@ class ForwardDateRefiner { ;// ./node_modules/chrono-node/dist/esm/common/refiners/UnlikelyFormatFilter.js class UnlikelyFormatFilter extends Filter { + strictMode; constructor(strictMode) { super(); this.strictMode = strictMode; @@ -2835,12 +2639,6 @@ class UnlikelyFormatFilter extends Filter { }); return false; } - if (result.start.isOnlyTime() && (!result.start.isCertain("hour") || !result.start.isCertain("minute"))) { - context.debug(() => { - console.log(`(Strict) Removing uncertain time component: ${result} (${result.end})`); - }); - return false; - } return true; } } @@ -2935,88 +2733,92 @@ function includeCommonConfiguration(configuration, strictMode = false) { return configuration; } ;// ./node_modules/chrono-node/dist/esm/common/casualReferences.js - +/* unused harmony import specifier */ var casualReferences_ParsingComponents; +/* unused harmony import specifier */ var casualReferences_assignSimilarDate; +/* unused harmony import specifier */ var casualReferences_Meridiem; function now(reference) { - const targetDate = dayjs_min(reference.instant); - const component = new results_ParsingComponents(reference, {}); - dayjs_assignSimilarDate(component, targetDate); + const targetDate = reference.getDateWithAdjustedTimezone(); + const component = new ParsingComponents(reference, {}); + assignSimilarDate(component, targetDate); assignSimilarTime(component, targetDate); - if (reference.timezoneOffset !== null) { - component.assign("timezoneOffset", targetDate.utcOffset()); - } + component.assign("timezoneOffset", reference.getTimezoneOffset()); component.addTag("casualReference/now"); return component; } function today(reference) { - const targetDate = dayjs_min(reference.instant); - const component = new results_ParsingComponents(reference, {}); - dayjs_assignSimilarDate(component, targetDate); + const targetDate = reference.getDateWithAdjustedTimezone(); + const component = new ParsingComponents(reference, {}); + assignSimilarDate(component, targetDate); implySimilarTime(component, targetDate); + component.delete("meridiem"); component.addTag("casualReference/today"); return component; } function yesterday(reference) { return theDayBefore(reference, 1).addTag("casualReference/yesterday"); } -function theDayBefore(reference, numDay) { - return theDayAfter(reference, -numDay); -} function tomorrow(reference) { return theDayAfter(reference, 1).addTag("casualReference/tomorrow"); } +function theDayBefore(reference, numDay) { + return theDayAfter(reference, -numDay); +} function theDayAfter(reference, nDays) { - let targetDate = dayjs_min(reference.instant); - const component = new results_ParsingComponents(reference, {}); - targetDate = targetDate.add(nDays, "day"); - dayjs_assignSimilarDate(component, targetDate); - implySimilarTime(component, targetDate); + const targetDate = reference.getDateWithAdjustedTimezone(); + const component = new ParsingComponents(reference, {}); + const newDate = new Date(targetDate.getTime()); + newDate.setDate(newDate.getDate() + nDays); + assignSimilarDate(component, newDate); + implySimilarTime(component, newDate); + component.delete("meridiem"); return component; } function tonight(reference, implyHour = 22) { - const targetDate = dayjs_min(reference.instant); - const component = new results_ParsingComponents(reference, {}); - dayjs_assignSimilarDate(component, targetDate); + const targetDate = reference.getDateWithAdjustedTimezone(); + const component = new ParsingComponents(reference, {}); + assignSimilarDate(component, targetDate); component.imply("hour", implyHour); - component.imply("meridiem", types_Meridiem.PM); + component.imply("meridiem", Meridiem.PM); component.addTag("casualReference/tonight"); return component; } function lastNight(reference, implyHour = 0) { - let targetDate = dayjs(reference.instant); - const component = new ParsingComponents(reference, {}); - if (targetDate.hour() < 6) { - targetDate = targetDate.add(-1, "day"); + let targetDate = reference.getDateWithAdjustedTimezone(); + const component = new casualReferences_ParsingComponents(reference, {}); + if (targetDate.getHours() < 6) { + targetDate = new Date(targetDate.getTime() - 24 * 60 * 60 * 1000); } - assignSimilarDate(component, targetDate); + casualReferences_assignSimilarDate(component, targetDate); component.imply("hour", implyHour); return component; } function evening(reference, implyHour = 20) { - const component = new results_ParsingComponents(reference, {}); - component.imply("meridiem", types_Meridiem.PM); + const component = new ParsingComponents(reference, {}); + component.imply("meridiem", Meridiem.PM); component.imply("hour", implyHour); component.addTag("casualReference/evening"); return component; } function yesterdayEvening(reference, implyHour = 20) { - let targetDate = dayjs(reference.instant); - const component = new ParsingComponents(reference, {}); - targetDate = targetDate.add(-1, "day"); - assignSimilarDate(component, targetDate); + let targetDate = reference.getDateWithAdjustedTimezone(); + const component = new casualReferences_ParsingComponents(reference, {}); + targetDate = new Date(targetDate.getTime() - 24 * 60 * 60 * 1000); + casualReferences_assignSimilarDate(component, targetDate); component.imply("hour", implyHour); - component.imply("meridiem", Meridiem.PM); + component.imply("meridiem", casualReferences_Meridiem.PM); component.addTag("casualReference/yesterday"); component.addTag("casualReference/evening"); return component; } function midnight(reference) { - const component = new results_ParsingComponents(reference, {}); - const targetDate = dayjs_min(reference.instant); - if (targetDate.hour() > 2) { - implyTheNextDay(component, targetDate); + const component = new ParsingComponents(reference, {}); + if (reference.getDateWithAdjustedTimezone().getHours() > 2) { + component.addDurationAsImplied({ + day: 1 + }); } component.assign("hour", 0); component.imply("minute", 0); @@ -3026,8 +2828,8 @@ function midnight(reference) { return component; } function morning(reference, implyHour = 6) { - const component = new results_ParsingComponents(reference, {}); - component.imply("meridiem", types_Meridiem.AM); + const component = new ParsingComponents(reference, {}); + component.imply("meridiem", Meridiem.AM); component.imply("hour", implyHour); component.imply("minute", 0); component.imply("second", 0); @@ -3036,8 +2838,8 @@ function morning(reference, implyHour = 6) { return component; } function afternoon(reference, implyHour = 15) { - const component = new results_ParsingComponents(reference, {}); - component.imply("meridiem", types_Meridiem.PM); + const component = new ParsingComponents(reference, {}); + component.imply("meridiem", Meridiem.PM); component.imply("hour", implyHour); component.imply("minute", 0); component.imply("second", 0); @@ -3046,9 +2848,9 @@ function afternoon(reference, implyHour = 15) { return component; } function noon(reference) { - const component = new results_ParsingComponents(reference, {}); - component.imply("meridiem", types_Meridiem.AM); - component.imply("hour", 12); + const component = new ParsingComponents(reference, {}); + component.imply("meridiem", Meridiem.AM); + component.assign("hour", 12); component.imply("minute", 0); component.imply("second", 0); component.imply("millisecond", 0); @@ -3059,14 +2861,13 @@ function noon(reference) { - -const ENCasualDateParser_PATTERN = /(now|today|tonight|tomorrow|tmr|tmrw|yesterday|last\s*night)(?=\W|$)/i; +const ENCasualDateParser_PATTERN = /(now|today|tonight|tomorrow|overmorrow|tmr|tmrw|yesterday|last\s*night)(?=\W|$)/i; class ENCasualDateParser extends AbstractParserWithWordBoundaryChecking { innerPattern(context) { return ENCasualDateParser_PATTERN; } innerExtract(context, match) { - let targetDate = dayjs_min(context.refDate); + let targetDate = context.refDate; const lowerText = match[0].toLowerCase(); let component = context.createParsingComponents(); switch (lowerText) { @@ -3087,12 +2888,17 @@ class ENCasualDateParser extends AbstractParserWithWordBoundaryChecking { case "tonight": component = tonight(context.reference); break; + case "overmorrow": + component = theDayAfter(context.reference, 2); + break; default: if (lowerText.match(/last\s*night/)) { - if (targetDate.hour() > 6) { - targetDate = targetDate.add(-1, "day"); + if (targetDate.getHours() > 6) { + const previousDay = new Date(targetDate.getTime()); + previousDay.setDate(previousDay.getDate() - 1); + targetDate = previousDay; } - dayjs_assignSimilarDate(component, targetDate); + assignSimilarDate(component, targetDate); component.imply("hour", 0); } break; @@ -3136,16 +2942,15 @@ class ENCasualTimeParser extends AbstractParserWithWordBoundaryChecking { return component; } } -;// ./node_modules/chrono-node/dist/esm/common/calculation/weekdays.js - +;// ./node_modules/chrono-node/dist/esm/calculation/weekdays.js function createParsingComponentsAtWeekday(reference, weekday, modifier) { const refDate = reference.getDateWithAdjustedTimezone(); const daysToWeekday = getDaysToWeekday(refDate, weekday, modifier); - let components = new results_ParsingComponents(reference); - components = addImpliedTimeUnits(components, { - "day": daysToWeekday + let components = new ParsingComponents(reference); + components = components.addDurationAsImplied({ + day: daysToWeekday }); components.assign("weekday", weekday); return components; @@ -3200,7 +3005,8 @@ function getBackwardDaysToWeekday(refDate, weekday) { -const ENWeekdayParser_PATTERN = new RegExp("(?:(?:\\,|\\(|\\()\\s*)?" + "(?:on\\s*?)?" + "(?:(this|last|past|next)\\s*)?" + `(${matchAnyPattern(WEEKDAY_DICTIONARY)})` + "(?:\\s*(?:\\,|\\)|\\)))?" + "(?:\\s*(this|last|past|next)\\s*week)?" + "(?=\\W|$)", "i"); + +const ENWeekdayParser_PATTERN = new RegExp("(?:(?:\\,|\\(|\\()\\s*)?" + "(?:on\\s*?)?" + "(?:(this|last|past|next)\\s*)?" + `(${matchAnyPattern(WEEKDAY_DICTIONARY)}|weekend|weekday)` + "(?:\\s*(?:\\,|\\)|\\)))?" + "(?:\\s*(this|last|past|next)\\s*week)?" + "(?=\\W|$)", "i"); const ENWeekdayParser_PREFIX_GROUP = 1; const WEEKDAY_GROUP = 2; const POSTFIX_GROUP = 3; @@ -3209,8 +3015,6 @@ class ENWeekdayParser extends AbstractParserWithWordBoundaryChecking { return ENWeekdayParser_PATTERN; } innerExtract(context, match) { - const dayOfWeek = match[WEEKDAY_GROUP].toLowerCase(); - const weekday = WEEKDAY_DICTIONARY[dayOfWeek]; const prefix = match[ENWeekdayParser_PREFIX_GROUP]; const postfix = match[POSTFIX_GROUP]; let modifierWord = prefix || postfix; @@ -3224,6 +3028,24 @@ class ENWeekdayParser extends AbstractParserWithWordBoundaryChecking { } else if (modifierWord == "this") { modifier = "this"; } + const weekday_word = match[WEEKDAY_GROUP].toLowerCase(); + let weekday; + if (WEEKDAY_DICTIONARY[weekday_word] !== undefined) { + weekday = WEEKDAY_DICTIONARY[weekday_word]; + } else if (weekday_word == "weekend") { + weekday = modifier == "last" ? Weekday.SUNDAY : Weekday.SATURDAY; + } else if (weekday_word == "weekday") { + const refWeekday = context.reference.getDateWithAdjustedTimezone().getDay(); + if (refWeekday == Weekday.SUNDAY || refWeekday == Weekday.SATURDAY) { + weekday = modifier == "last" ? Weekday.FRIDAY : Weekday.MONDAY; + } else { + weekday = refWeekday - 1; + weekday = modifier == "last" ? weekday - 1 : weekday + 1; + weekday = weekday % 5 + 1; + } + } else { + return null; + } return createParsingComponentsAtWeekday(context.reference, weekday, modifier); } } @@ -3232,7 +3054,6 @@ class ENWeekdayParser extends AbstractParserWithWordBoundaryChecking { - const ENRelativeDateFormatParser_PATTERN = new RegExp(`(this|last|past|next|after\\s*this)\\s*(${matchAnyPattern(TIME_UNIT_DICTIONARY)})(?=\\s*)` + "(?=\\W|$)", "i"); const MODIFIER_WORD_GROUP = 1; const RELATIVE_WORD_GROUP = 2; @@ -3247,31 +3068,31 @@ class ENRelativeDateFormatParser extends AbstractParserWithWordBoundaryChecking if (modifier == "next" || modifier.startsWith("after")) { const timeUnits = {}; timeUnits[timeunit] = 1; - return results_ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + return ParsingComponents.createRelativeFromReference(context.reference, timeUnits); } if (modifier == "last" || modifier == "past") { const timeUnits = {}; timeUnits[timeunit] = -1; - return results_ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + return ParsingComponents.createRelativeFromReference(context.reference, timeUnits); } const components = context.createParsingComponents(); - let date = dayjs_min(context.reference.instant); + let date = new Date(context.reference.instant.getTime()); if (unitWord.match(/week/i)) { - date = date.add(-date.get("d"), "d"); - components.imply("day", date.date()); - components.imply("month", date.month() + 1); - components.imply("year", date.year()); + date.setDate(date.getDate() - date.getDay()); + components.imply("day", date.getDate()); + components.imply("month", date.getMonth() + 1); + components.imply("year", date.getFullYear()); } else if (unitWord.match(/month/i)) { - date = date.add(-date.date() + 1, "d"); - components.imply("day", date.date()); - components.assign("year", date.year()); - components.assign("month", date.month() + 1); + date.setDate(1); + components.imply("day", date.getDate()); + components.assign("year", date.getFullYear()); + components.assign("month", date.getMonth() + 1); } else if (unitWord.match(/year/i)) { - date = date.add(-date.date() + 1, "d"); - date = date.add(-date.month(), "month"); - components.imply("day", date.date()); - components.imply("month", date.month() + 1); - components.assign("year", date.year()); + date.setDate(1); + date.setMonth(0); + components.imply("day", date.getDate()); + components.imply("month", date.getMonth() + 1); + components.assign("year", date.getFullYear()); } return components; } @@ -3285,6 +3106,8 @@ const FIRST_NUMBERS_GROUP = 2; const SECOND_NUMBERS_GROUP = 3; const SlashDateFormatParser_YEAR_GROUP = 4; class SlashDateFormatParser { + groupNumberMonth; + groupNumberDay; constructor(littleEndian) { this.groupNumberMonth = littleEndian ? SECOND_NUMBERS_GROUP : FIRST_NUMBERS_GROUP; this.groupNumberDay = littleEndian ? FIRST_NUMBERS_GROUP : SECOND_NUMBERS_GROUP; @@ -3339,7 +3162,7 @@ class SlashDateFormatParser { const year = findYearClosestToRef(context.refDate, day, month); result.start.imply("year", year); } - return result; + return result.addTag("parser/SlashDateFormatParser"); } } ;// ./node_modules/chrono-node/dist/esm/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js @@ -3350,6 +3173,7 @@ class SlashDateFormatParser { const ENTimeUnitCasualRelativeFormatParser_PATTERN = new RegExp(`(this|last|past|next|after|\\+|-)\\s*(${TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); const PATTERN_NO_ABBR = new RegExp(`(this|last|past|next|after|\\+|-)\\s*(${TIME_UNITS_NO_ABBR_PATTERN})(?=\\W|$)`, "i"); class ENTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundaryChecking { + allowAbbreviations; constructor(allowAbbreviations = true) { super(); this.allowAbbreviations = allowAbbreviations; @@ -3359,18 +3183,18 @@ class ENTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundar } innerExtract(context, match) { const prefix = match[1].toLowerCase(); - let timeUnits = parseTimeUnits(match[2]); - if (!timeUnits) { + let duration = parseDuration(match[2]); + if (!duration) { return null; } switch (prefix) { case "last": case "past": case "-": - timeUnits = reverseTimeUnits(timeUnits); + duration = reverseDuration(duration); break; } - return results_ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + return ParsingComponents.createRelativeFromReference(context.reference, duration); } } ;// ./node_modules/chrono-node/dist/esm/locales/en/refiners/ENMergeRelativeAfterDateRefiner.js @@ -3392,11 +3216,11 @@ class ENMergeRelativeAfterDateRefiner extends MergingRefiner { return IsPositiveFollowingReference(nextResult) || IsNegativeFollowingReference(nextResult); } mergeResults(textBetween, currentResult, nextResult, context) { - let timeUnits = parseTimeUnits(nextResult.text); + let timeUnits = parseDuration(nextResult.text); if (IsNegativeFollowingReference(nextResult)) { - timeUnits = reverseTimeUnits(timeUnits); + timeUnits = reverseDuration(timeUnits); } - const components = results_ParsingComponents.createRelativeFromReference(new ReferenceWithTimezone(currentResult.start.date()), timeUnits); + const components = ParsingComponents.createRelativeFromReference(ReferenceWithTimezone.fromDate(currentResult.start.date()), timeUnits); return new ParsingResult(currentResult.reference, currentResult.index, `${currentResult.text}${textBetween}${nextResult.text}`, components); } } @@ -3425,11 +3249,11 @@ class ENMergeRelativeFollowByDateRefiner extends MergingRefiner { return !!nextResult.start.get("day") && !!nextResult.start.get("month") && !!nextResult.start.get("year"); } mergeResults(textBetween, currentResult, nextResult) { - let timeUnits = parseTimeUnits(currentResult.text); + let duration = parseDuration(currentResult.text); if (hasImpliedEarlierReferenceDate(currentResult)) { - timeUnits = reverseTimeUnits(timeUnits); + duration = reverseDuration(duration); } - const components = results_ParsingComponents.createRelativeFromReference(new ReferenceWithTimezone(nextResult.start.date()), timeUnits); + const components = ParsingComponents.createRelativeFromReference(ReferenceWithTimezone.fromDate(nextResult.start.date()), duration); return new ParsingResult(nextResult.reference, currentResult.index, `${currentResult.text}${textBetween}${nextResult.text}`, components); } } @@ -3448,6 +3272,9 @@ class ENExtractYearSuffixRefiner { if (!match) { return; } + if (match[0].trim().length <= 3) { + return; + } context.debug(() => { console.log(`Extracting year: '${match[0]}' into : ${result}`); }); @@ -3461,6 +3288,38 @@ class ENExtractYearSuffixRefiner { return results; } } +;// ./node_modules/chrono-node/dist/esm/locales/en/refiners/ENUnlikelyFormatFilter.js + +class ENUnlikelyFormatFilter extends Filter { + constructor() { + super(); + } + isValid(context, result) { + const text = result.text.trim(); + if (text === context.text.trim()) { + return true; + } + if (text.toLowerCase() === "may") { + const textBefore = context.text.substring(0, result.index).trim(); + if (!textBefore.match(/\b(in)$/i)) { + context.debug(() => { + console.log(`Removing unlikely result: ${result}`); + }); + return false; + } + } + if (text.toLowerCase().endsWith("the second")) { + const textAfter = context.text.substring(result.index + result.text.length).trim(); + if (textAfter.length > 0) { + context.debug(() => { + console.log(`Removing unlikely result: ${result}`); + }); + } + return false; + } + return true; + } +} ;// ./node_modules/chrono-node/dist/esm/locales/en/configuration.js @@ -3482,6 +3341,7 @@ class ENExtractYearSuffixRefiner { + class ENDefaultConfiguration { @@ -3492,6 +3352,7 @@ class ENDefaultConfiguration { option.parsers.push(new ENMonthNameParser()); option.parsers.push(new ENRelativeDateFormatParser()); option.parsers.push(new ENTimeUnitCasualRelativeFormatParser()); + option.refiners.push(new ENUnlikelyFormatFilter()); return option; } createConfiguration(strictMode = true, littleEndian = false) { @@ -3513,8 +3374,10 @@ class ENDefaultConfiguration { class Chrono { + parsers; + refiners; + defaultConfig = new ENDefaultConfiguration(); constructor(configuration) { - this.defaultConfig = new ENDefaultConfiguration(); configuration = configuration || this.defaultConfig.createCasualConfiguration(); this.parsers = [...configuration.parsers]; this.refiners = [...configuration.refiners]; @@ -3562,7 +3425,7 @@ class Chrono { let parsedResult = null; if (result instanceof ParsingResult) { parsedResult = result; - } else if (result instanceof results_ParsingComponents) { + } else if (result instanceof ParsingComponents) { parsedResult = context.createParsingResult(match.index, match[0]); parsedResult.start = result; } else { @@ -3579,17 +3442,21 @@ class Chrono { } } class ParsingContext { + text; + option; + reference; + refDate; constructor(text, refDate, option) { this.text = text; - this.reference = new ReferenceWithTimezone(refDate); this.option = option ?? {}; + this.reference = ReferenceWithTimezone.fromInput(refDate, this.option.timezones); this.refDate = this.reference.instant; } createParsingComponents(components) { - if (components instanceof results_ParsingComponents) { + if (components instanceof ParsingComponents) { return components; } - return new results_ParsingComponents(this.reference, components); + return new ParsingComponents(this.reference, components); } createParsingResult(index, textOrEndIndex, startComponents, endComponents) { const text = typeof textOrEndIndex === "string" ? textOrEndIndex : this.text.substring(index, textOrEndIndex); @@ -3642,6 +3509,8 @@ function parseDate(text, ref, option) { + + const esm_strict = strict; const esm_casual = casual; function esm_parse(text, ref, option) { @@ -3760,9 +3629,9 @@ const constants_TIME_UNIT_DICTIONARY = { std: "hour", stunde: "hour", stunden: "hour", - tag: "d", - tage: "d", - tagen: "d", + tag: "day", + tage: "day", + tagen: "day", woche: "week", wochen: "week", monat: "month", @@ -3816,7 +3685,7 @@ function constants_parseYear(match) { const constants_SINGLE_TIME_UNIT_PATTERN = `(${constants_NUMBER_PATTERN})\\s{0,5}(${matchAnyPattern(constants_TIME_UNIT_DICTIONARY)})\\s{0,5}`; const constants_SINGLE_TIME_UNIT_REGEX = new RegExp(constants_SINGLE_TIME_UNIT_PATTERN, "i"); const constants_TIME_UNITS_PATTERN = repeatedTimeunitPattern("", constants_SINGLE_TIME_UNIT_PATTERN); -function constants_parseTimeUnits(timeunitText) { +function constants_parseDuration(timeunitText) { const fragments = {}; let remainingText = timeunitText; let match = constants_SINGLE_TIME_UNIT_REGEX.exec(remainingText); @@ -3909,31 +3778,31 @@ class DESpecificTimeExpressionParser { return null; } if (hour >= 12) { - meridiem = types_Meridiem.PM; + meridiem = Meridiem.PM; } if (match[DESpecificTimeExpressionParser_AM_PM_HOUR_GROUP] != null) { if (hour > 12) return null; const ampm = match[DESpecificTimeExpressionParser_AM_PM_HOUR_GROUP].toLowerCase(); if (ampm.match(/morgen|vormittag/)) { - meridiem = types_Meridiem.AM; + meridiem = Meridiem.AM; if (hour == 12) { hour = 0; } } if (ampm.match(/nachmittag|abend/)) { - meridiem = types_Meridiem.PM; + meridiem = Meridiem.PM; if (hour != 12) { hour += 12; } } if (ampm.match(/nacht/)) { if (hour == 12) { - meridiem = types_Meridiem.AM; + meridiem = Meridiem.AM; hour = 0; } else if (hour < 6) { - meridiem = types_Meridiem.AM; + meridiem = Meridiem.AM; } else { - meridiem = types_Meridiem.PM; + meridiem = Meridiem.PM; hour += 12; } } @@ -3944,9 +3813,9 @@ class DESpecificTimeExpressionParser { extractingComponents.assign("meridiem", meridiem); } else { if (hour < 12) { - extractingComponents.imply("meridiem", types_Meridiem.AM); + extractingComponents.imply("meridiem", Meridiem.AM); } else { - extractingComponents.imply("meridiem", types_Meridiem.PM); + extractingComponents.imply("meridiem", Meridiem.PM); } } if (match[DESpecificTimeExpressionParser_SECOND_GROUP] != null) { @@ -3975,14 +3844,12 @@ class DEMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner { - - class DECasualTimeParser extends AbstractParserWithWordBoundaryChecking { innerPattern(context) { return /(diesen)?\s*(morgen|vormittag|mittags?|nachmittag|abend|nacht|mitternacht)(?=\W|$)/i; } innerExtract(context, match) { - const targetDate = dayjs_min(context.refDate); + const targetDate = context.refDate; const timeKeywordPattern = match[2].toLowerCase(); const component = context.createParsingComponents(); implySimilarTime(component, targetDate); @@ -3994,49 +3861,49 @@ class DECasualTimeParser extends AbstractParserWithWordBoundaryChecking { component.imply("hour", 6); component.imply("minute", 0); component.imply("second", 0); - component.imply("meridiem", types_Meridiem.AM); + component.imply("meridiem", Meridiem.AM); break; case "vormittag": component.imply("hour", 9); component.imply("minute", 0); component.imply("second", 0); - component.imply("meridiem", types_Meridiem.AM); + component.imply("meridiem", Meridiem.AM); break; case "mittag": case "mittags": component.imply("hour", 12); component.imply("minute", 0); component.imply("second", 0); - component.imply("meridiem", types_Meridiem.AM); + component.imply("meridiem", Meridiem.AM); break; case "nachmittag": component.imply("hour", 15); component.imply("minute", 0); component.imply("second", 0); - component.imply("meridiem", types_Meridiem.PM); + component.imply("meridiem", Meridiem.PM); break; case "abend": component.imply("hour", 18); component.imply("minute", 0); component.imply("second", 0); - component.imply("meridiem", types_Meridiem.PM); + component.imply("meridiem", Meridiem.PM); break; case "nacht": component.imply("hour", 22); component.imply("minute", 0); component.imply("second", 0); - component.imply("meridiem", types_Meridiem.PM); + component.imply("meridiem", Meridiem.PM); break; case "mitternacht": if (component.get("hour") > 1) { - component = addImpliedTimeUnits(component, { + component.addDurationAsImplied({ "day": 1 }); } component.imply("hour", 0); component.imply("minute", 0); component.imply("second", 0); - component.imply("meridiem", types_Meridiem.AM); + component.imply("meridiem", Meridiem.AM); break; } return component; @@ -4056,7 +3923,7 @@ class DECasualDateParser extends AbstractParserWithWordBoundaryChecking { return DECasualDateParser_PATTERN; } innerExtract(context, match) { - let targetDate = dayjs_min(context.refDate); + let targetDate = context.reference.getDateWithAdjustedTimezone(); const dateKeyword = (match[DECasualDateParser_DATE_GROUP] || "").toLowerCase(); const timeKeyword = (match[TIME_GROUP] || "").toLowerCase(); let component = context.createParsingComponents(); @@ -4068,29 +3935,42 @@ class DECasualDateParser extends AbstractParserWithWordBoundaryChecking { component = today(context.reference); break; case "morgen": - assignTheNextDay(component, targetDate); + targetDate = addDuration(targetDate, { + day: 1 + }); + assignSimilarDate(component, targetDate); + implySimilarTime(component, targetDate); break; case "übermorgen": case "uebermorgen": - targetDate = targetDate.add(1, "day"); - assignTheNextDay(component, targetDate); + targetDate = addDuration(targetDate, { + day: 2 + }); + assignSimilarDate(component, targetDate); + implySimilarTime(component, targetDate); break; case "gestern": - targetDate = targetDate.add(-1, "day"); - dayjs_assignSimilarDate(component, targetDate); + targetDate = addDuration(targetDate, { + day: -1 + }); + assignSimilarDate(component, targetDate); implySimilarTime(component, targetDate); break; case "vorgestern": - targetDate = targetDate.add(-2, "day"); - dayjs_assignSimilarDate(component, targetDate); + targetDate = addDuration(targetDate, { + day: -2 + }); + assignSimilarDate(component, targetDate); implySimilarTime(component, targetDate); break; default: if (dateKeyword.match(/letzte\s*nacht/)) { - if (targetDate.hour() > 6) { - targetDate = targetDate.add(-1, "day"); + if (targetDate.getHours() > 6) { + targetDate = addDuration(targetDate, { + day: -1 + }); } - dayjs_assignSimilarDate(component, targetDate); + assignSimilarDate(component, targetDate); component.imply("hour", 0); } break; @@ -4165,9 +4045,9 @@ class DETimeUnitAgoFormatParser extends AbstractParserWithWordBoundaryChecking { return; } if (/vor/.test(modifier) || /letzte/.test(modifier) || /vergangen/.test(modifier)) { - timeUnits = reverseTimeUnits(timeUnits); + timeUnits = reverseDuration(timeUnits); } - return results_ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + return ParsingComponents.createRelativeFromReference(context.reference, timeUnits); } } ;// ./node_modules/chrono-node/dist/esm/locales/de/parsers/DETimeUnitWithinFormatParser.js @@ -4179,8 +4059,8 @@ class DETimeUnitWithinFormatParser extends AbstractParserWithWordBoundaryCheckin return new RegExp(`(?:in|für|während)\\s*(${constants_TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); } innerExtract(context, match) { - const timeUnits = constants_parseTimeUnits(match[1]); - return results_ParsingComponents.createRelativeFromReference(context.reference, timeUnits); + const timeUnits = constants_parseDuration(match[1]); + return ParsingComponents.createRelativeFromReference(context.reference, timeUnits); } } ;// ./node_modules/chrono-node/dist/esm/locales/de/index.js @@ -4264,10 +4144,15 @@ function parseRawHeaders(h) { return new Headers(array); } function parseGMResponse(req, res) { - return new ResImpl(res.response, { + // workaround TamperMonkey bug(?) where sometimes response is string despite responseType being "blob" + const headers = parseRawHeaders(res.responseHeaders); + const body = typeof res.response === "string" + ? new Blob([res.response], { type: headers.get("Content-Type") || "text/plain" }) + : res.response; + return new ResImpl(body, { statusCode: res.status, statusText: res.statusText, - headers: parseRawHeaders(res.responseHeaders), + headers, finalUrl: res.finalUrl, redirected: res.finalUrl === req.url, }); @@ -4334,6 +4219,13 @@ class ResImpl { this._bodyUsed = true; return this.rawBody.text(); } + async bytes() { + if (this.bodyUsed) { + throw new TypeError("Failed to execute 'bytes' on 'Response': body stream already read"); + } + this._bodyUsed = true; + return new Uint8Array(await this.rawBody.arrayBuffer()); + } } function decode(body) { const form = new FormData(); @@ -4371,7 +4263,12 @@ function XHR(request, init, data) { data: data, responseType: "blob", onload(res) { - resolve(parseGMResponse(request, res)); + try { + resolve(parseGMResponse(request, res)); + } + catch (e) { + reject(e); + } }, onabort() { reject(new DOMException("Aborted", "AbortError")); @@ -4400,10 +4297,17 @@ function gmXHRMethod(method) { //# sourceMappingURL=index.mjs.map +;// ./src/config.ts +class _Config { + tapi_server_url = 'https://3cxtapi.cp-austria.at'; +} +const Config = new _Config(); + ;// ./src/call-history.ts + class CallHistory { callerIds = {}; updateCallHistoryEntry(call, callerId) { @@ -4478,7 +4382,7 @@ class CallHistory { this.updateCallHistoryEntry(element, this.callerIds[number]); } else { - var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number)); + var response = await GM_fetch(Config.tapi_server_url + '/callerid/' + encodeURIComponent(number)); var callerId = { tD_NAME: '' }; if (response.status === 200) { callerId = await response.json(); @@ -4493,6 +4397,7 @@ class CallHistory { ;// ./src/call-notification.ts + class CallNotification { async showCallNotification(element) { var number = element.querySelector('.callNumber').textContent; @@ -4503,7 +4408,7 @@ class CallNotification { return; } console.log('TAPI searching callerid for', number); - var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number)); + var response = await GM_fetch(Config.tapi_server_url + '/callerid/' + encodeURIComponent(number)); console.log('TAPI callerid response', response); var notification = { text: number @@ -4583,6 +4488,7 @@ function debounce(func, wait) { + class Search { currentSearchText = ''; createSearchWindow(element) { @@ -4677,7 +4583,7 @@ class Search { return; } console.log('Searching TAPI'); - var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/search?query=' + encodeURIComponent(searchText)); + var response = await GM_fetch(Config.tapi_server_url + '/search?query=' + encodeURIComponent(searchText)); console.log('TAPI Search response', response); var contacts = await response.json(); console.log('TAPI Contacts', contacts); @@ -4752,6 +4658,7 @@ var status_update = injectStylesIntoStyleTag_default()(cjs_js_src_status/* defau ;// ./src/status.ts + class Status { _user; _enabled = false; @@ -4770,7 +4677,7 @@ class Status { async checkStatus() { if (this._enabled) { try { - var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/availability/' + encodeURIComponent(this._user)); + var response = await GM_fetch(Config.tapi_server_url + '/availability/' + encodeURIComponent(this._user)); if (response.status == 200) { var status = await response.json(); if (this._currentStatus !== status.loggedIn) { @@ -4891,6 +4798,33 @@ class Status { this._currentStatus = undefined; }; } + watchStatus(element) { + console.log('updateFavicon watching', element); + const attrObserver = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if (mutation.attributeName === 'class') { + this.updateStatus(element); + } + }); + }); + attrObserver.observe(element, { attributes: true }); + this.updateStatus(element); + } + updateStatus(element) { + console.log('Status changed', element.classList); + var color = window.getComputedStyle(element).getPropertyValue("background-color"); + console.log('Background color:', color); + this.setFaviconColor(color); + } + setFaviconColor(color) { + var link = document.querySelector("link[rel~='icon']"); + if (!link) { + link = document.createElement('link'); + link.rel = 'icon'; + document.head.appendChild(link); + } + link.href = "data:image/svg+xml,%3Csvg width='32px' height='32px' xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cpolyline points='9,0 20,0 32,16 20,32 9,32, 20,16' fill='" + encodeURIComponent(color) + "' id='MyLine' /%3E%3C/svg%3E"; + } } ;// ./src/index.js @@ -4921,7 +4855,8 @@ const src_status_0 = new Status(); waitForKeyElements('wc-account-menu', element => { src_status_0.showStatus(element); }, false); -})(); - +waitForKeyElements('wc-account-menu i.status-indicator', element => { + src_status_0.watchStatus(element); +}, false); /******/ })() ; \ No newline at end of file