Categories: JavaScript

About A Bot

screen-shot-2016-10-25-at-12-31-49-pm

The Timebot is finished.

I make use of three different and important bits of code that are written by other people. First off, of course, is Botkit by Howdy.ai.

Then, because I make a habit never to do work I don’t have to, there are two different APIs that take dates and return differences between them. Rob Eberhardt’s jsDate is an attempt to emulate VBScript’s date and time functions. Also along those lines is Adam Phillips’ dateDiff but it returns the timespan as a set of years, months, and days.

I did have to make one change to jsDate. In the DateDiff method, he uses ParseInt() to get integer values from floating point values. I’m not sure why this was done, but this leads to some incorrect values. Using  Math.round() however, works better for these purposes because ParseInt will truncate digits after a decimal point, acting as a Math.floor(). We don’t want Math.floor.

 var nMilliseconds = iDiffMS;
 var nSeconds = Math.round(iDiffMS / 1000);
 var nMinutes = Math.round(nSeconds / 60);
 var nHours = Math.round(nMinutes / 60);
 var nDays = Math.round(nHours / 24);
 var nWeeks = Math.round(nDays / 7);

I’m not sure what the methodology is for rounding the values after division at each step. This may even add a small amount of error into the equation at each step, leading to larger errors further down. I didn’t spend a lot of time on it, since I didn’t discover errors after I switched from ParseInt() to Math.round().

How did I check for errors? I entered test dates and checked the return values with Wolfram Alpha. I figure if Wolfram is wrong, there is no beauty or truth in the universe.

This works. It’s not perfect. The engineering changed a couple of times during the process. I saw an appropriate quote by way of Daring Fireball yesterday. It’s a quote from Dave Winer.

An old software slogan at Living Videotext: “We Make Shitty Software… With Bugs!” It makes me laugh! We never ran this slogan in an ad. People wouldn’t understand. But it’s the truth. We make shitty software. And so do you!

Software is a process, it’s never finished, it’s always evolving. That’s its nature. We know our software sucks. But it’s shipping! Next time we’ll do better, but even then it will be shitty. The only software that’s perfect is one you’re dreaming about. Real software crashes, loses data, is hard to learn and hard to use. But it’s a process. We’ll make it less shitty. Just watch!

This is true for all work, really. Every project is an unfinished work. There is always something that could be better. However, at some point we have to release, that’s why we make deadlines. Even today with eternal beta-quality software is an admission that projects are always incomplete. What’s important is that we release this snapshot, meet our goals for today, and set our sights higher for tomorrow. Never give up, and never go back.

img_1554

Here is the code, it works “as is”.

coda_js_icon   time_bot_jie_1.js

 

Article info