Bladeren bron

docs: datetime rejects impossible offsets and non-numeric amounts

fszontagh 1 maand geleden
bovenliggende
commit
11d12995f1

+ 13 - 3
docs/superpowers/plans/2026-08-04-tier-1-nodes.md

@@ -2615,7 +2615,7 @@ const configSchema = {
         secondField: {
             type: 'string',
             title: 'Second Date Field',
-            description: 'Path to the date to compare against, for the diff operation'
+            description: 'Path to the date to compare against, for the diff operation. diff returns the input date minus this one, so a later input gives a positive result'
         },
         format: {
             type: 'string',
@@ -2696,7 +2696,13 @@ function offsetMinutes(offset) {
     if (!match) {
         throw new Error('Date and Time: offset must look like +02:00, got "' + offset + '"');
     }
-    const minutes = parseInt(match[2], 10) * 60 + parseInt(match[3], 10);
+    const hours = parseInt(match[2], 10);
+    const mins = parseInt(match[3], 10);
+    if (hours > 14 || mins > 59) {
+        throw new Error('Date and Time: offset "' + offset +
+            '" is out of range. Real offsets run from -12:00 to +14:00');
+    }
+    const minutes = hours * 60 + mins;
     return match[1] === '-' ? -minutes : minutes;
 }
 
@@ -2775,7 +2781,11 @@ async function execute(config, input, context) {
         return result;
     }
 
-    const delta = (Number(config.amount) || 0) * step;
+    const amount = Number(config.amount);
+    if (isNaN(amount)) {
+        throw new Error('Date and Time: amount must be a number, got "' + config.amount + '"');
+    }
+    const delta = amount * step;
     const shifted = operation === 'subtract' ? timestamp - delta : timestamp + delta;
     result[outputField] = formatTimestamp(shifted, pattern, offset);
     result.timestamp = shifted;

+ 1 - 1
docs/superpowers/specs/2026-08-04-tier-1-nodes-design.md

@@ -136,7 +136,7 @@ re-interpolate.
 
 QuickJS here is Bellard's build with no ICU (`cmake/Dependencies.cmake`), so
 `Intl` does not exist and named zones like `Europe/Budapest` cannot be resolved.
-`datetime.js` supports UTC, host local time, and explicit `+02:00` style offsets,
+`datetime.js` supports UTC and explicit `+02:00` style offsets,
 and says so in its description. Shipping a DST rule table inside the node was
 rejected: it goes stale silently when a country changes policy.