Node-Red Node that produces a nicely formatted Date/Time string using the Moment.JS library & is fully time zone/DST/locale aware.
Based on thoughts from a conversation in the Node-Red Google Group. Updated with timezone/locale capabilities after Jaques44's initial work. Updated with +/- adjustments after another conversion in the Google Group.
Run the following command in the root directory of your Node-RED install
npm install node-red-contrib-moment
If you want to install the original version:
npm install node-red-contrib-moment@1
While in development, install with:
npm install https://github.com/TotallyInformation/node-red-contrib-moment/tarball/master
2017-12-12 16:03:51.832427000 -0400as well as the Twitter API default time string:
Mon Jan 08 21:24:37 +0000 2018(contributed by Steve Rickus). Update dependencies.
The node generally expects an input from the incoming msg. By default, this is msg.payload. If it is a recognisable date/time, it will apply a format and output the resulting string or object accordingly.
Input and output time zones are settable as is the output locale. All of which default to the host systems tz/locale.
This allows the node to be used to translate from one time zone to another. It also will take into account daylight savings time (DST).
You can also apply an adjustment to the date/time by adding or subtracting an amount.
See the node's built-in help for more details.
Specify the input variable to execute humanize on,
msg.payload.humanized will contain a humanized version of the specified span in seconds. (Contributed by Laro88)
Summary of things I'd like to do with the moment node (not necessarily immediately):
Add some additional nodes for doing date/time calculations - partly complete, can do simple add/subtract from main node
Add additional node for doing duration calculations
Add a combo box to the Format field with common formats pre-populated
Improve the error messages when Moment.JS fails to interpret the input (say why)
Allow more input date/time formats - turns out Moment.JS doesn't really help here. At present, I see too many input failures from US/UK date formats, etc. It would be great if I could parse "human" inputs like "tomorrow" and "2 minutes from now". We can output them now but not input them. As of v1.0.5, a localisation parameter is supported.
Partly complete: Added the parseFormat plugin. That failed, see code for details. Now complete.
This code is Open Source under an Apache 2 License. Please see the apache2-license.txt file for details.
You may not use this code except in compliance with the License. You may obtain an original copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Please see the License for the specific language governing permissions and limitations under the License.
Many thanks for the contributions.
Please report any issues or suggestions via the Github Issues list for this repository.
For more information, feedback, or community support see the Node-Red Google groups forum at https://groups.google.com/forum/#!forum/node-red