mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
fd7a25e1ac
* New 'request' tag and a lot of improvements * Update request extension to render all values * Custom value of tag editor now inherits current
36 lines
842 B
JavaScript
36 lines
842 B
JavaScript
export default {
|
|
name: 'now',
|
|
displayName: 'Timestamp',
|
|
description: 'get the current time',
|
|
args: [{
|
|
displayName: 'Timestamp Format',
|
|
type: 'enum',
|
|
options: [
|
|
{displayName: 'ISO-8601', value: 'iso-8601'},
|
|
{displayName: 'Milliseconds', value: 'millis'},
|
|
{displayName: 'Unix', value: 'unix'}
|
|
]
|
|
}],
|
|
run (context, dateType = 'iso-8601') {
|
|
if (typeof dateType === 'string') {
|
|
dateType = dateType.toLowerCase();
|
|
}
|
|
|
|
const now = new Date();
|
|
|
|
switch (dateType) {
|
|
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();
|
|
default:
|
|
throw new Error(`Invalid date type "${dateType}"`);
|
|
}
|
|
}
|
|
};
|