fix(wired): date-range condition saved NaN for empty/invalid dates

The save guard `if(startDateInstance && endDateInstance)` is always true — a bad
input parses to a truthy *Invalid Date*, so `getTime()/1000` wrote NaN into the
int params. A never-configured furni was worse: the read effect only seeded the
inputs when `intData.length >= 2`, so the first save sent `new Date('')` → NaN.
Guard on `isNaN(getTime())` and seed both inputs to "now" for the empty case.
This commit is contained in:
simoleo89
2026-06-13 16:53:36 +02:00
parent 728eceab65
commit 742f7ee5f7
@@ -13,35 +13,34 @@ export const WiredConditionDateRangeView: FC<{}> = props =>
const save = () =>
{
let startDateMili = 0;
let endDateMili = 0;
const startDateInstance = new Date(startDate);
const endDateInstance = new Date(endDate);
if(startDateInstance && endDateInstance)
{
startDateMili = startDateInstance.getTime() / 1000;
endDateMili = endDateInstance.getTime() / 1000;
}
// new Date('garbage') is a truthy *Invalid Date*, not null — the old
// `if(startDateInstance && endDateInstance)` was always true, so an
// unparseable input wrote NaN as the int param. Guard on getTime().
const startDateMili = isNaN(startDateInstance.getTime()) ? 0 : Math.floor(startDateInstance.getTime() / 1000);
const endDateMili = isNaN(endDateInstance.getTime()) ? 0 : Math.floor(endDateInstance.getTime() / 1000);
setIntParams([ startDateMili, endDateMili ]);
};
useEffect(() =>
{
if(trigger.intData.length >= 2)
{
// Seed both inputs (default "now") even for a never-configured furni so
// the first save can't send new Date('') → NaN.
let startDate = new Date();
let endDate = new Date();
if(trigger.intData.length >= 2)
{
if(trigger.intData[0] > 0) startDate = new Date((trigger.intData[0] * 1000));
if(trigger.intData[1] > 0) endDate = new Date((trigger.intData[1] * 1000));
}
setStartDate(WiredDateToString(startDate));
setEndDate(WiredDateToString(endDate));
}
}, [ trigger ]);
return (