Read Timestamp In 116 Languages In The Console

Gabin Desserprit
Data Hunter’s Blog
2 min readAug 12, 2017

If you’re a dev, you probably come along timestamps a lot. They’re great to save datetime but horrible to read. Ladies and gentlemen, I decided to take 10 minutes of my time to save a lot more — and hopefully save you some to!

Wanna test it along the article? simply npm install timestamp-cmd -g or check it out there timestamp-cmd.

Building

As a javascript developer I had never tried to build a command-line tool. I knew that was doable though. I came accross commander and that was it.

Commander helps you build the structure of your command-line tool by setting up flags and automatically parsing arguments.

You can then simply add functions and output the data you want depending on the parameters you got!

I’ve set up 2 flags, one for the language -l and one for the format -f.

Improving

Then I thought it would be cool to actually store some settings that the user would set for himself.

I simply made a config.json file (and a default.config.json) in which one I would simply update the user config.

In order to dynamically update it I added 2 new flags in uppercase for long time use of the previous flags : language -L and format -F.

I also made it possible to reset the configuration to the default one via a simple flag -R .

Shell command

So far you’ve seen me using ts [timestamp] plus some flags. But it would work that way if I hadn’t added something to my package.json : the bin property.

It simply makes your package executable. You can either set the file path (to it would use your package name) or give it an object with as the key your command name and the file path as value.

Check out the npm doc for more information : Bin Property.

Publishing

Well to make live a long life as an open source project (and mostly to be able to find it back quickly and install it on any machine), I pushed it to Github and then NPM.

Feel free to install the lib npm install timestamp-cmd -g and share the love by recommending this to your community & friends with a upvote!

If you liked it, you might also like my previous and next articles about Javascript, Node.js, Web Scraping and Automation.

Follow me, I don’t mind.

Gabin Desserprit
Data Hunter / Linkedin

--

--