mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
8452e8b777
* Fixed duplication kve bug * Some changes * Add proptypes linting * Fixed proptypes even more * Filename linting
31 lines
672 B
JavaScript
31 lines
672 B
JavaScript
import BaseExtension from './base/base-extension';
|
|
|
|
export default class NowExtension extends BaseExtension {
|
|
constructor () {
|
|
super();
|
|
this.tags = ['now'];
|
|
}
|
|
|
|
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}"`);
|
|
}
|
|
}
|
|
}
|