Are you using seconds or milliseconds? Don’t lose a Mars orbiter over it!

Aniket Kadam
1 min readJul 5, 2018

--

If you need an object that includes time, you’re probably going to need to convert it. Unit conversion is the cause of many bugs, some more disastrous than others.

When designing software, always make the right thing easy and the wrong thing hard.

(CNN) — NASA lost a $125 million Mars orbiter because a Lockheed Martin engineering team used English units of measurement while the agency’s team used the more conventional metric system for a key spacecraft operation

What if you never had to bother about which one it was and would get it right 100% of the time no matter if you needed milliseconds or hours?
Here’s how.

Let’s presume you’re measuring exercise duration.

Duration can never be set or accessed without specifying what units you’re sending or asking for.

What you get from using this pattern is, it’s impossible to mess up saving or getting information from that object.

It doesn’t matter what internal representation you choose. You’ll never go wrong in either setting or getting time out because you choose a unit each time you actually need it.

You’ll never go wrong in either setting or getting time out because you choose a unit each time you actually need it.

Caution Points

Ask me questions on Twitter or comment below!

--

--

Aniket Kadam

Software Engineer with an eye on business. I’ve helped startups build their apps from the ground up. Available for consulting.