fix(runtime): Passing in invalid date to "Date To String" node causes node scope to fail (#75)

This commit is contained in:
Eric Tuvesson
2024-09-23 21:11:32 +02:00
committed by GitHub
parent a98e381f8c
commit d80870e835

View File

@@ -31,8 +31,6 @@ const DateToStringNode = {
this._internal.currentInput = _value; this._internal.currentInput = _value;
this._format(); this._format();
this.flagOutputDirty('currentValue');
this.sendSignalOnOutput('inputChanged');
} }
} }
}, },
@@ -49,30 +47,45 @@ const DateToStringNode = {
type: 'signal', type: 'signal',
displayName: 'Date Changed', displayName: 'Date Changed',
group: 'Signals' group: 'Signals'
},
onError: {
type: 'signal',
displayName: 'Invalid Date',
group: 'Signals'
} }
}, },
methods: { methods: {
_format() { _format() {
const t = this._internal.currentInput; try {
const format = this._internal.formatString; const t = this._internal.currentInput;
const date = ('0' + t.getDate()).slice(-2); const format = this._internal.formatString;
const month = ('0' + (t.getMonth() + 1)).slice(-2); const date = ('0' + t.getDate()).slice(-2);
const monthShort = new Intl.DateTimeFormat('en-US', { month: 'short' }).format(t); const month = ('0' + (t.getMonth() + 1)).slice(-2);
const year = t.getFullYear(); const monthShort = new Intl.DateTimeFormat('en-US', { month: 'short' }).format(t);
const yearShort = year.toString().substring(2); const year = t.getFullYear();
const hours = ('0' + t.getHours()).slice(-2); const yearShort = year.toString().substring(2);
const minutes = ('0' + t.getMinutes()).slice(-2); const hours = ('0' + t.getHours()).slice(-2);
const seconds = ('0' + t.getSeconds()).slice(-2); const minutes = ('0' + t.getMinutes()).slice(-2);
const seconds = ('0' + t.getSeconds()).slice(-2);
this._internal.dateString = format this._internal.dateString = format
.replace(/\{date\}/g, date) .replace(/\{date\}/g, date)
.replace(/\{month\}/g, month) .replace(/\{month\}/g, month)
.replace(/\{monthShort\}/g, monthShort) .replace(/\{monthShort\}/g, monthShort)
.replace(/\{year\}/g, year) .replace(/\{year\}/g, year)
.replace(/\{yearShort\}/g, yearShort) .replace(/\{yearShort\}/g, yearShort)
.replace(/\{hours\}/g, hours) .replace(/\{hours\}/g, hours)
.replace(/\{minutes\}/g, minutes) .replace(/\{minutes\}/g, minutes)
.replace(/\{seconds\}/g, seconds); .replace(/\{seconds\}/g, seconds);
} catch (error) {
// Set the output to be blank, makes it easier to handle.
this._internal.dateString = '';
this.flagOutputDirty('onError');
}
// Flag that the value have changed
this.flagOutputDirty('currentValue');
this.sendSignalOnOutput('inputChanged');
} }
} }
}; };