-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsimpletime.html
363 lines (360 loc) · 16.3 KB
/
simpletime.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<script type="text/javascript">
RED.nodes.registerType('simpletime',{
category: 'function',
color: '#87A980',
defaults: {
name: {value:""},
mydate: {value:true},
myymd: {value:true},
myyear: {value:true},
mymonth: {value:true},
mymonthn: {value:true},
mymonthf: {value:true},
mydom: {value:true},
mydoy: {value:true},
myday: {value:true},
mydayf: {value:true},
myhourpm: {value:true},
myhour: {value:true},
mytime: {value:true},
mytimes: {value:true},
myminute: {value:true},
myminutes: {value:true},
mysecond: {value:true},
mymillis: {value:true},
myepoch: {value:true},
myrawdate: {value:true},
mypm: {value:true}
},
inputs:1,
outputs:1,
icon: "time.png",
label: function() {
return this.name||"simpletime";
},
oneditprepare: function() {
if (this.mydate === undefined) {
this.mydate = true;
$("#node-input-mydate").prop('checked', true);
}
if (this.myymd === undefined) {
this.myymd = true;
$("#node-input-myymd").prop('checked', true);
}
if (this.myyear === undefined) {
this.myyear = true;
$("#node-input-myyear").prop('checked', true);
}
if (this.mymonth === undefined) {
this.mymonth = true;
$("#node-input-mymonth").prop('checked', true);
}
if (this.mymonthf === undefined) {
this.mymonthf = true;
$("#node-input-mymonthf").prop('checked', true);
}
if (this.mymonthn === undefined) {
this.mymonthn = true;
$("#node-input-mymonthn").prop('checked', true);
}
if (this.mydom === undefined) {
this.mydom = true;
$("#node-input-mydom").prop('checked', true);
}
if (this.mydoy === undefined) {
this.mydoy = true;
$("#node-input-mydoy").prop('checked', true);
}
if (this.myday === undefined) {
this.myday = true;
$("#node-input-myday").prop('checked', true);
}
if (this.mydayf === undefined) {
this.mydayf = true;
$("#node-input-mydayf").prop('checked', true);
}
if (this.myhourpm === undefined) {
this.myhourpm = true;
$("#node-input-myhourpm").prop('checked', true);
}
if (this.myhour === undefined) {
this.myhour = true;
$("#node-input-myhour").prop('checked', true);
}
if (this.mytime === undefined) {
this.mytime = true;
$("#node-input-mytime").prop('checked', true);
}
if (this.mytimes === undefined) {
this.mytimes = true;
$("#node-input-mytimes").prop('checked', true);
}
if (this.myminute === undefined) {
this.myminute = true;
$("#node-input-myminute").prop('checked', true);
}
if (this.myminutes === undefined) {
this.myminutes = true;
$("#node-input-myminutes").prop('checked', true);
}
if (this.mysecond === undefined) {
this.mysecond = true;
$("#node-input-mysecond").prop('checked', true);
}
if (this.mymillis === undefined) {
this.mymillis = true;
$("#node-input-mymillis").prop('checked', true);
}
if (this.myepoch === undefined) {
this.myepoch = true;
$("#node-input-myepoch").prop('checked', true);
}
if (this.myrawdate === undefined) {
this.myrawdate = true;
$("#node-input-myrawdate").prop('checked', true);
}
if (this.mypm === undefined) {
this.mypm = true;
$("#node-input-mypm").prop('checked', true);
}
}
});
</script>
<script type="text/javascript">
function selectAll() {
this.mydate = true;
$("#node-input-mydate").prop('checked', true);
this.myymd = true;
$("#node-input-myymd").prop('checked', true);
this.myyear = true;
$("#node-input-myyear").prop('checked', true);
this.mymonth = true;
$("#node-input-mymonth").prop('checked', true);
this.mymonthn = true;
$("#node-input-mymonthn").prop('checked', true);
this.mymonthf = true;
$("#node-input-mymonthf").prop('checked', true);
this.mydom = true;
$("#node-input-mydom").prop('checked', true);
this.mydoy = true;
$("#node-input-mydoy").prop('checked', true);
this.myday = true;
$("#node-input-myday").prop('checked', true);
this.mydayf = true;
$("#node-input-mydayf").prop('checked', true);
this.myhourpm = true;
$("#node-input-myhourpm").prop('checked', true);
this.myhour = true;
$("#node-input-myhour").prop('checked', true);
this.mytime = true;
$("#node-input-mytime").prop('checked', true);
this.mytimes = true;
$("#node-input-mytimes").prop('checked', true);
this.myminute = true;
$("#node-input-myminute").prop('checked', true);
this.myminutes = true;
$("#node-input-myminutes").prop('checked', true);
this.mysecond = true;
$("#node-input-mysecond").prop('checked', true);
this.mymillis = true;
$("#node-input-mymillis").prop('checked', true);
this.myepoch = true;
$("#node-input-myepoch").prop('checked', true);
this.myrawdate = true;
$("#node-input-myrawdate").prop('checked', true);
this.mypm = true;
$("#node-input-mypm").prop('checked', true);
};
function deselectAll() {
this.mydate = false;
$("#node-input-mydate").prop('checked', false);
this.myymd = false;
$("#node-input-myymd").prop('checked', false);
this.myyear = false;
$("#node-input-myyear").prop('checked', false);
this.mymonth = false;
$("#node-input-mymonth").prop('checked', false);
this.mymonthn = false;
$("#node-input-mymonthn").prop('checked', false);
this.mydom = false;
$("#node-input-mymonthf").prop('checked', false);
this.mydom = false;
$("#node-input-mydom").prop('checked', false);
this.mydoy = false;
$("#node-input-mydoy").prop('checked', false);
this.myday = false;
$("#node-input-myday").prop('checked', false);
this.mydayf = false;
$("#node-input-mydayf").prop('checked', false);
this.myhourpm = false;
$("#node-input-myhourpm").prop('checked', false);
this.myhour = false;
$("#node-input-myhour").prop('checked', false);
this.mytime = false;
$("#node-input-mytime").prop('checked', false);
this.mytimes = false;
$("#node-input-mytimes").prop('checked', false);
this.myminute = false;
$("#node-input-myminute").prop('checked', false);
this.myminutes = false;
$("#node-input-myminutes").prop('checked', false);
this.mysecond = false;
$("#node-input-mysecond").prop('checked', false);
this.mymillis = false;
$("#node-input-mymillis").prop('checked', false);
this.myepoch = false;
$("#node-input-myepoch").prop('checked', false);
this.myrawdate = false;
$("#node-input-myrawdate").prop('checked', false);
this.mypm = false;
$("#node-input-mypm").prop('checked', false);
};
</script>
<script type="text/x-red" data-template-name="simpletime">
<div class="form-row" style="min-width: 540px">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<button onClick="selectAll()" type="button" class="red-ui-button">Select All</button>    <button onClick="deselectAll()" type="button" class="red-ui-button">Clear All</button>
<br/>
<br/>
<label style="width:100%; display:inline"; <span>Include the following properties in the message:</span></label>
<br/>
<br/>
<div style="display: flex;">
<div style="flex-grow: 1;">
<div class="form-row">
<input type="checkbox" id="node-input-mydate" style="width:15px;">
<label for="node-input-mydate" style="display:inline"> mydate e.g. "Tue Sep 11 2018"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-myyear" style="width:15px;">
<label for="node-input-myyear" style="display:inline"> myyear e.g. "2018"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mymonthn" style="width:15px;">
<label for="node-input-mymonthn" style="display:inline"> mymonthn e.g. "09"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mymonth" style="width:15px;">
<label for="node-input-mymonth" style="display:inline"> mymonth e.g. "Sep"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mymonthf" style="width:15px;">
<label for="node-input-mymonthf" style="display:inline"> mymonthf e.g. "September"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mydoy" style="width:15px;">
<label for="node-input-mydoy" style="display:inline"> mydoy e.g. "86"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-myhourpm" style="width:15px;">
<label for="node-input-myhourpm" style="width:30%; display:inline"> myhourpm e.g. "7"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mytime" style="width:15px;">
<label for="node-input-mytime" style="width:30%; display:inline"> mytime e.g. "19:51"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-myminute" style="width:15px;">
<label for="node-input-myminute" style="width:30%; display:inline"> myminute e.g. "51"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mysecond" style="width:15px;">
<label for="node-input-mysecond" style="width:30%; display:inline"> mysecond e.g. "17"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-myepoch" style="width:15px;">
<label for="node-input-myepoch" style="width:30%; display:inline"> myepoch e.g. "1536691877064"</label>
</div>
</div>
<div style="flex-grow: 1;">
<div class="form-row">
<input type="checkbox" id="node-input-myymd" style="width:15px;">
<label for="node-input-myymd" style="display:inline"> myymd e.g. "2018-09-11"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mydom" style="width:15px;">
<label for="node-input-mydom" style="display:inline"> mydom e.g. "11"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-myday" style="width:15px;">
<label for="node-input-myday" style="width:30%; display:inline"> myday e.g. "Tue"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mydayf" style="width:15px;">
<label for="node-input-mydayf" style="width:30%; display:inline"> mydayf e.g. "Tuesday"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-myhour" style="width:15px;">
<label for="node-input-myhour" style="width:30%; display:inline"> myhour e.g. "19"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mytimes" style="width:15px;">
<label for="node-input-mytimes" style="width:30%; display:inline"> mytimes e.g. "19:51:17"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-myminutes" style="width:15px;">
<label for="node-input-myminutes" style="width:30%; display:inline"> myminutes e.g. "51:17"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mymillis" style="width:15px;">
<label for="node-input-mymillis" style="width:30%; display:inline"> mymillis e.g. "985"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-myrawdate" style="width:15px;">
<label for="node-input-myrawdate" style="width:30%; display:inline"> myrawdate e.g. "2018-09-11T18:51:17.064Z"</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-mypm" style="width:15px;">
<label for="node-input-mypm" style="width:30%; display:inline"> mypm e.g. "PM"</label>
</div>
</div>
</div>
</script>
<script type="text/x-red" data-help-name="simpletime">
<p>Simpletime node is an extremely lightweight node which can be inserted in any running flow, and adds time and date payloads with various formatting options, which can be retreived and used later in the flow.</p>
<p>For more advanced timezone handling, <code>node-red-contrib-moment</code> is recommended.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>payload</dt>
<dd>Any existing payloads or topics being injected into simpletime will pass unaltered through the node, except msg.date</dd>
<dd>If msg.date is present, the node expects it to contain a date in a format that can be parsed as a date object by the new Date() constructor, such as 2024-04-16T12:02:05Z or a timestamp 1715538265198 (as a number)</dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>payload
<span class="property-type">as per input</span>
</dt>
<dd>In addition to any existing payloads, a number of additional payloads will be added, which can be utilised later in the flow. </dd>
<dd>By default, all the additional properties will be added to the message but this can be altered in the node configuration, using checkboxes.</dd>
</dl>
<h3>Details</h3>
<p>The additional payloads added to the flow, and their typical content format are;</p>
<ul>
<li>msg.mydate: "Tue Sep 11 2018"</li>
<li>msg.myymd: "2018-09-11"</li>
<li>msg.myyear: "2018"</li>
<li>msg.mymonth: "Sep"</li>
<li>msg.mymonthf: "September"</li>
<li>msg.mymonthn: "09"</li>
<li>msg.mydom: "11"</li>
<li>msg.mydoy: "86"</li>
<li>msg.myday: "Tue"</li>
<li>msg.mydayf: "Tuesday"</li>
<li>msg.myhourpm: "7"</li>
<li>msg.myhour: "19"</li>
<li>msg.mytime: "19:51"</li>
<li>msg.mytimes: "19:51:17"</li>
<li>msg.myminute: "51"</li>
<li>msg.myminutes: "51:17"</li>
<li>msg.mysecond: "17"</li>
<li>msg.mymillis: "985"</li>
<li>msg.myepoch: "1536691877064"</li>
<li>msg.myrawdate: "2018-09-11T18:51:17.064Z"</li>
<li>msg.mypm: "PM"</li>
</ul>
<p>To introduce any of the messages into a flow, simply assign any, or any combination of the messages into a variable, such as; <code>var seconds = msg.myseconds;</code>
or to use in a ui_text node add via mustache <code>{{msg.mytimes}}</code></p>
<p>More advanced date formats can also be constructed, such as <code>{{mytime}}hrs - {{mydom}}/{{mymonth}}</code> to get "20:10hrs - 11/Sep", or <code>{{myhourpm}}:{{myminute}}{{mypm}}</code> to get "8.10PM"</p>
</script>