Initial commit

Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com>
Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com>
Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com>
Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com>
Co-Authored-By: Johan  <4934465+joolsus@users.noreply.github.com>
Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com>
Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
This commit is contained in:
Michael Cartner
2024-01-26 11:52:55 +01:00
commit b9c60b07dc
2789 changed files with 868795 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
'use strict';
const DateToStringNode = {
name: 'Date To String',
docs: 'https://docs.noodl.net/nodes/utilities/date-to-string',
category: 'Utilities',
initialize: function () {
this._internal.formatString = '{year}-{month}-{date}';
},
inputs: {
formatString: {
displayName: 'Format',
type: 'string',
default: '{year}-{month}-{date}',
set: function (value) {
if (this._internal.formatString === value) return;
this._internal.formatString = value;
if (this._internal.currentInput !== undefined) {
this._format();
this.flagOutputDirty('currentValue');
}
}
},
input: {
type: { name: 'date' },
displayName: 'Date',
set: function (value) {
const _value = typeof value === 'string' ? new Date(value) : value;
if (this._internal.currentInput === _value) return;
this._internal.currentInput = _value;
this._format();
this.flagOutputDirty('currentValue');
this.sendSignalOnOutput('inputChanged');
}
}
},
outputs: {
currentValue: {
type: 'string',
displayName: 'Date String',
group: 'Value',
getter: function () {
return this._internal.dateString;
}
},
inputChanged: {
type: 'signal',
displayName: 'Date Changed',
group: 'Signals'
}
},
methods: {
_format() {
const t = this._internal.currentInput;
const format = this._internal.formatString;
const date = ('0' + t.getDate()).slice(-2);
const month = ('0' + (t.getMonth() + 1)).slice(-2);
const monthShort = new Intl.DateTimeFormat('en-US', { month: 'short' }).format(t);
const year = t.getFullYear();
const hours = ('0' + t.getHours()).slice(-2);
const minutes = ('0' + t.getMinutes()).slice(-2);
const seconds = ('0' + t.getSeconds()).slice(-2);
this._internal.dateString = format
.replace(/\{date\}/g, date)
.replace(/\{month\}/g, month)
.replace(/\{monthShort\}/g, monthShort)
.replace(/\{year\}/g, year)
.replace(/\{hours\}/g, hours)
.replace(/\{minutes\}/g, minutes)
.replace(/\{seconds\}/g, seconds);
}
}
};
module.exports = {
node: DateToStringNode
};