insomnia/app/templating/extensions/NowExtension.js
Gregory Schier bb57f360e0 Environment Tags and Such (#90)
* Sort of working nunjucks editor

* Some more tweaks

* Lots of stuff

* Gettingn pretty good

* Minor tweaks and test fixes

* Minor bug fixes and stuff

* Some fixes and perf

* Refactoring

* Good for now

* Codemirror URL

* More and more fixes and improvements

* Code single-line CSS perfect!!!

* Better nj editing

* Show preview in nj edit

* Some editor updates

* All inputs now covered

* A bunch of fixes and stuff

* Don't cache node modules because it's not needed

* More stuff

* Tweak

* Style tweaks

* Pull nunjucks mode into own file

* Move codemirror click overlay to own file

* Pull nunjucks tag stuff out

* Fixed key value editor

* raw/endraw and marks improvements

* Some tweaks
2017-02-27 13:00:13 -08:00

31 lines
671 B
JavaScript

import BaseExtension from './base/BaseExtension';
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}"`);
}
}
}