Skip to content

Commit

Permalink
Manual integration of Jacques44 pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
TotallyInformation committed Jun 12, 2016
1 parent 5b8f607 commit f537efa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 8 additions & 2 deletions moment/nrmoment.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
<label for="node-input-locale"><i class="fa fa-flag"></i> Locale</label>
<input type="text" id="node-input-locale" placeholder="en">
</div>
<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-fakeUTC" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-fakeUTC" style="width: 70%;">Consider UTC string as local</label>
</div>
<div class="form-tips">
Default output format is ISO8601 if the input is a Date object and is a Date object if the input is a string.
See the info sidebar for formatting details.
Expand All @@ -88,7 +93,7 @@
<p>Format an input date-time message object.</p>
<p>
<b>Input</b> must be either a JS datetime object or a <a href="http://momentjs.com/docs/#/parsing/">string that Moment.js can resolve to such</a>.
If the input is null, doesn't exist or is a blank string, the current Date/Time will be used. This can be used to add a current timestamp to a
If the input is null, doesn not exist or is a blank string, the current Date/Time will be used. This can be used to add a current timestamp to a
flow of any kind easily.
</p>
<p>
Expand Down Expand Up @@ -124,7 +129,8 @@
input: {value:"payload"},
format: {value:""},
locale: {value:""},
output: {value:"payload"}
output: {value:"payload"},
fakeUTC: {value: false }
},
inputs:1, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
Expand Down
10 changes: 6 additions & 4 deletions moment/nrmoment.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ module.exports = function(RED) {
// copy "this" object in case we need it in context of callbacks of other functions.
var node = this;

if (n.locale) {
moment.locale(n.locale);
}

// send out the message to the rest of the workspace.
// ... this message will get sent at startup so you may not see it in a debug node.
// Define OUTPUT msg...
Expand Down Expand Up @@ -93,6 +89,12 @@ module.exports = function(RED) {
// Get a Moment.JS date/time - NB: the result might not be
// valid since the input might not parse as a date/time
var mDT = moment(inp);
if (n.locale) mDT.locale(n.locale);

// Jacques44: This hack is for those who store local date as UTC string
// Not pretty I know but mongoimport only knows UTC string and my programs don't...
if (n.fakeUTC) mDT = moment(mDT.toISOString().slice(0,-1));

// Check if the input is a date?
if ( ! mDT.isValid() ) {
node.warn('The input property was NOT a recognisable date. Output will be a blank string');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-moment",
"version": "1.0.8",
"version": "1.0.9",
"description": "Node-Red Node that produces a nicely formatted Date/Time string using the Moment.JS library.",
"dependencies": {
"moment": "2.x"
Expand Down

0 comments on commit f537efa

Please sign in to comment.