@tachybase/utils 1.6.12 → 1.6.13-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/parse-filter.js +18 -6
- package/package.json +1 -1
package/lib/parse-filter.js
CHANGED
|
@@ -209,22 +209,34 @@ function getDayRange(options) {
|
|
|
209
209
|
];
|
|
210
210
|
}
|
|
211
211
|
__name(getDayRange, "getDayRange");
|
|
212
|
-
function toMoment(value
|
|
212
|
+
function toMoment(value) {
|
|
213
213
|
if (!value) {
|
|
214
|
-
return
|
|
214
|
+
return (0, import_dayjs.default)();
|
|
215
215
|
}
|
|
216
216
|
if (import_dayjs.default.isDayjs(value)) {
|
|
217
217
|
return value;
|
|
218
218
|
}
|
|
219
|
-
return
|
|
219
|
+
return (0, import_dayjs.default)(value);
|
|
220
220
|
}
|
|
221
221
|
__name(toMoment, "toMoment");
|
|
222
|
+
function toIsoWeekLabel(m) {
|
|
223
|
+
const [year, month, day] = m.format("YYYY-MM-DD").split("-").map(Number);
|
|
224
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
225
|
+
date.setUTCDate(date.getUTCDate() + 4 - (date.getUTCDay() || 7));
|
|
226
|
+
const isoYear = date.getUTCFullYear();
|
|
227
|
+
const yearStart = new Date(Date.UTC(isoYear, 0, 1));
|
|
228
|
+
const isoWeek = Math.ceil(((date.getTime() - yearStart.getTime()) / 864e5 + 1) / 7);
|
|
229
|
+
return `${isoYear}W${String(isoWeek).padStart(2, "0")}`;
|
|
230
|
+
}
|
|
231
|
+
__name(toIsoWeekLabel, "toIsoWeekLabel");
|
|
222
232
|
function utc2unit(options) {
|
|
223
233
|
var _a;
|
|
224
234
|
const { now, unit, timezone = "+00:00", offset } = options;
|
|
225
|
-
let m = toMoment(now
|
|
235
|
+
let m = toMoment(now);
|
|
226
236
|
m = m.utcOffset((0, import_date.offsetFromString)(timezone));
|
|
227
|
-
|
|
237
|
+
if (unit !== "isoWeek") {
|
|
238
|
+
m = m.startOf(unit);
|
|
239
|
+
}
|
|
228
240
|
if (offset > 0) {
|
|
229
241
|
m = m.add(offset, unit === "isoWeek" ? "week" : unit);
|
|
230
242
|
} else if (offset < 0) {
|
|
@@ -235,7 +247,7 @@ function utc2unit(options) {
|
|
|
235
247
|
quarter: /* @__PURE__ */ __name(() => m.format("YYYY[Q]Q"), "quarter"),
|
|
236
248
|
month: /* @__PURE__ */ __name(() => m.format("YYYY-MM"), "month"),
|
|
237
249
|
week: /* @__PURE__ */ __name(() => m.format("gggg[w]ww"), "week"),
|
|
238
|
-
isoWeek: /* @__PURE__ */ __name(() => m
|
|
250
|
+
isoWeek: /* @__PURE__ */ __name(() => toIsoWeekLabel(m), "isoWeek"),
|
|
239
251
|
day: /* @__PURE__ */ __name(() => m.format("YYYY-MM-DD"), "day")
|
|
240
252
|
};
|
|
241
253
|
const r = (_a = fn[unit]) == null ? void 0 : _a.call(fn);
|