@timeback/core 0.2.3-beta.20260326015342 → 0.2.3-beta.20260326022000
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.
|
@@ -39,7 +39,17 @@ function getTimezoneOffsetMs(at, timezone) {
|
|
|
39
39
|
const localMs = Date.UTC(n("year"), n("month") - 1, n("day"), n("hour"), n("minute"), n("second"));
|
|
40
40
|
return at.getTime() - at.getTime() % 1000 - localMs;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function validateBareDate(bareDate, fieldName) {
|
|
43
|
+
const [year, month, day] = bareDate.split("-").map(Number);
|
|
44
|
+
const d = new Date(Date.UTC(year, month - 1, day));
|
|
45
|
+
if (d.getUTCFullYear() !== year || d.getUTCMonth() !== month - 1 || d.getUTCDate() !== day) {
|
|
46
|
+
throw createInputValidationError("Invalid date", [
|
|
47
|
+
{ path: fieldName, message: `Not a valid calendar date: "${bareDate}"` }
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function bareDateToUTC(bareDate, time, timezone, fieldName) {
|
|
52
|
+
validateBareDate(bareDate, fieldName);
|
|
43
53
|
try {
|
|
44
54
|
const [year, month, day] = bareDate.split("-").map(Number);
|
|
45
55
|
const [h, m, secMs] = time.split(":");
|
|
@@ -59,19 +69,23 @@ function bareDateToUTC(bareDate, time, timezone) {
|
|
|
59
69
|
throw err;
|
|
60
70
|
}
|
|
61
71
|
}
|
|
62
|
-
function normalizeStartDate(date, timezone) {
|
|
72
|
+
function normalizeStartDate(date, timezone, fieldName = "startDate") {
|
|
63
73
|
if (date.includes("T"))
|
|
64
74
|
return date;
|
|
75
|
+
validateBareDate(date, fieldName);
|
|
65
76
|
if (!timezone)
|
|
66
77
|
return `${date}T00:00:00.000Z`;
|
|
67
|
-
return bareDateToUTC(date, "00:00:00.000", timezone);
|
|
78
|
+
return bareDateToUTC(date, "00:00:00.000", timezone, fieldName);
|
|
68
79
|
}
|
|
69
|
-
function normalizeEndDate(date, timezone) {
|
|
70
|
-
if (date.includes("T"))
|
|
80
|
+
function normalizeEndDate(date, timezone, fieldName = "endDate") {
|
|
81
|
+
if (date.includes("T")) {
|
|
71
82
|
return date;
|
|
72
|
-
|
|
83
|
+
}
|
|
84
|
+
validateBareDate(date, fieldName);
|
|
85
|
+
if (!timezone) {
|
|
73
86
|
return `${date}T23:59:59.999Z`;
|
|
74
|
-
|
|
87
|
+
}
|
|
88
|
+
return bareDateToUTC(date, "23:59:59.999", timezone, fieldName);
|
|
75
89
|
}
|
|
76
90
|
function aggregateActivityMetrics(data) {
|
|
77
91
|
const result = {
|
|
@@ -1961,7 +1975,7 @@ class AnalyticsResource {
|
|
|
1961
1975
|
params: {
|
|
1962
1976
|
email: validated.email,
|
|
1963
1977
|
studentId: validated.studentId,
|
|
1964
|
-
weekDate: normalizeStartDate(validated.weekDate, validated.timezone),
|
|
1978
|
+
weekDate: normalizeStartDate(validated.weekDate, validated.timezone, "weekDate"),
|
|
1965
1979
|
timezone: validated.timezone
|
|
1966
1980
|
}
|
|
1967
1981
|
});
|
package/dist/index.js
CHANGED
package/dist/utils.js
CHANGED