2017-06-15 19:10:19 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
|
2017-06-01 02:04:27 +00:00
|
|
|
export default {
|
|
|
|
name: 'now',
|
2017-06-09 01:10:12 +00:00
|
|
|
displayName: 'Timestamp',
|
2017-06-01 02:04:27 +00:00
|
|
|
description: 'get the current time',
|
2017-06-15 19:10:19 +00:00
|
|
|
args: [
|
|
|
|
{
|
|
|
|
displayName: 'Timestamp Format',
|
|
|
|
type: 'enum',
|
|
|
|
options: [
|
|
|
|
{displayName: 'ISO-8601', value: 'iso-8601'},
|
|
|
|
{displayName: 'Milliseconds', value: 'millis'},
|
|
|
|
{displayName: 'Unix', value: 'unix'},
|
|
|
|
{displayName: 'Custom Format', value: 'custom'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
help: 'moment.js format string',
|
|
|
|
displayName: 'Custom Format Template',
|
|
|
|
type: 'string',
|
|
|
|
placeholder: 'MMMM Do YYYY, h:mm:ss a',
|
|
|
|
hide: args => args[0].value !== 'custom'
|
|
|
|
}
|
|
|
|
],
|
2017-06-15 19:16:03 +00:00
|
|
|
run (context, dateType = 'iso-8601', formatStr = '') {
|
2017-02-27 21:00:13 +00:00
|
|
|
if (typeof dateType === 'string') {
|
|
|
|
dateType = dateType.toLowerCase();
|
|
|
|
}
|
|
|
|
|
2017-02-20 18:32:27 +00:00
|
|
|
const now = new Date();
|
|
|
|
|
2017-02-27 21:00:13 +00:00
|
|
|
switch (dateType) {
|
2017-02-20 18:32:27 +00:00
|
|
|
case 'millis':
|
|
|
|
case 'ms':
|
|
|
|
return now.getTime();
|
|
|
|
case 'unix':
|
|
|
|
case 'seconds':
|
|
|
|
case 's':
|
|
|
|
return Math.round(now.getTime() / 1000);
|
|
|
|
case 'iso-8601':
|
|
|
|
return now.toISOString();
|
2017-06-15 19:10:19 +00:00
|
|
|
case 'custom':
|
|
|
|
return moment(now).format(formatStr);
|
2017-02-27 21:00:13 +00:00
|
|
|
default:
|
|
|
|
throw new Error(`Invalid date type "${dateType}"`);
|
2017-02-20 18:32:27 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-01 02:04:27 +00:00
|
|
|
};
|