Adding Datejs to Scriptable?

Drafts uses Datejs to make manipulating dates easy.

I’d like to import the whole Datejs module into some of my Scriptable scripts. I’ve reviewed the documentation on importModule but I’m having trouble determining which files I need to download from the github repo above, and what code I may need to add (like module.export.add(something?) in order to make it usable by other scripts in Scriptable.

Any help would be appreciated. (Even better, would be integration of Datejs into Scriptable itself, akin to what Drafts has done.)


If I take the raw content of datejs, and save it to a file called date (or more accurately date.js) in Scriptable, I can then add the following line after the comments, and successfully call a datejs function as below.

//Add this to datejs; not sure if this is good practice to be doing this with "Date", but anyhow...
module.exports.Date = Date;
//Put this in a new Scriptable file, to import the module and bind it to 'datejs'
const datejs = importModule("date.js");

There could well be a better option, but I’ve only ever tried to use my own modules in Scriptable specifically, and I’ve always defined the exports myself as I’ve gone along. The above feels like it is a bit of a retrofit and feels clunky to me.

You could use the direct evaluation I used before we had importModule() and that should get you out of the extra datejs object use each time - if you just use the functions directly at the end of the date.js file that’s the same basis as the direct evaluation. I’m not recommending this approach. Direct evaluation is definitely kinda hacky. I’m just noting it as an option.

Hope something in that helps.

1 Like

Got it working, thanks!

Now to add some beautiful time tracking charts using Scriptable, Charty, and Shortcuts…