nodebb-plugin-equipment-calendar 8.1.0 → 8.1.2

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/library.js CHANGED
@@ -45,6 +45,33 @@ function normalizeItemIds(itemIdsRaw) {
45
45
  }
46
46
  }
47
47
 
48
+
49
+ function parseDateInput(v) {
50
+ if (v === null || v === undefined) return null;
51
+ if (typeof v === 'number' || (typeof v === 'string' && v.trim() && /^\d+$/.test(v.trim()))) {
52
+ const ms = typeof v === 'number' ? v : parseInt(v.trim(), 10);
53
+ const d = new Date(ms);
54
+ return Number.isNaN(d.getTime()) ? null : d;
55
+ }
56
+ if (typeof v === 'string') {
57
+ const s = v.trim();
58
+ if (!s) return null;
59
+ if (/^\d{4}-\d{2}-\d{2}$/.test(s)) {
60
+ const d = new Date(s + 'T00:00:00Z');
61
+ return Number.isNaN(d.getTime()) ? null : d;
62
+ }
63
+ const d = new Date(s);
64
+ return Number.isNaN(d.getTime()) ? null : d;
65
+ }
66
+ try {
67
+ const d = new Date(String(v));
68
+ return Number.isNaN(d.getTime()) ? null : d;
69
+ } catch (e) {
70
+ return null;
71
+ }
72
+ }
73
+
74
+
48
75
  const axios = require('axios');
49
76
  const { DateTime } = require('luxon');
50
77
  const { v4: uuidv4 } = require('uuid');
@@ -1199,12 +1226,12 @@ async function handleCreateReservation(req, res) {
1199
1226
  if (!itemIds.length) return res.status(400).send('itemIds required');
1200
1227
 
1201
1228
  // Dates come from modal as YYYY-MM-DD
1202
- const startStr = String(req.body.start || req.body.startDate || req.body.startIso || '');
1203
- const endStr = String(req.body.end || req.body.endDate || req.body.endIso || '');
1204
- if (!startStr || !endStr) return res.status(400).send('dates required');
1229
+ const startVal = req.body.start || req.body.startDate || req.body.startIso || req.body.startMs || req.body.startTime || '';
1230
+ const endVal = req.body.end || req.body.endDate || req.body.endIso || req.body.endMs || req.body.endTime || '';
1231
+ const start = parseDateInput(startVal);
1232
+ const end = parseDateInput(endVal);
1233
+ if (!start || !end) return res.status(400).send('dates required');
1205
1234
 
1206
- const start = new Date(startStr + 'T00:00:00Z');
1207
- const end = new Date(endStr + 'T00:00:00Z');
1208
1235
  const startMs = Date.UTC(start.getUTCFullYear(), start.getUTCMonth(), start.getUTCDate());
1209
1236
  let endMs = Date.UTC(end.getUTCFullYear(), end.getUTCMonth(), end.getUTCDate());
1210
1237
  if (endMs <= startMs) endMs = startMs + 24 * 60 * 60 * 1000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-equipment-calendar",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "description": "Equipment reservation calendar for NodeBB (FullCalendar, approvals, HelloAsso payments)",
5
5
  "main": "library.js",
6
6
  "scripts": {
package/plugin.json CHANGED
@@ -25,6 +25,6 @@
25
25
  "scripts": [
26
26
  "public/js/client.js"
27
27
  ],
28
- "version": "3.0.0-stable4b",
28
+ "version": "3.0.0-stable4c-datefix",
29
29
  "minver": "4.7.1"
30
30
  }