Your leaking thatched hut during the restoration of a pre-Enlightenment state.


Hello, my name is Judas Gutenberg and this is my blaag (pronounced as you would the vomit noise "hyroop-bleuach").


decay & ruin
Biosphere II
dead malls
Irving housing

got that wrong

appropriate tech
Arduino μcontrollers
Backwoods Home
Fractal antenna

fun social media stuff

(nobody does!)

Like my brownhouse:
   to and from timestamps
Monday, August 10 2015
She saw Eleanor scratching today so Gretchen ran a flea comb through her fur and found that the habitat at the base of Eleanor's tail was crawling with small black insects that can hop but cannot fly. It was a veritable Fleaghazi. So we had to initiate another Fleajad, poisoning all the critters with that oily chemical that goes in the space they can't lick between their scapulæ. The last time we'd done this was only three weeks ago, suggesting either the anti-flea poison we've been using is weak or that the fleas are strong (much like the state of the nation).
Today I worked at the task of converting datetimes as produced in a human-readable form by a DS1307 realtime clock into timestamps and then back to human readable again. This was so I could concisely timestamp weather data records as they're stored on a micro SD card and then later turn those timestamps back into a human-readable form. With most programming environments that I work with (such as Javascript, MySQL, PHP, and Objective C), there is a built-in codebase for doing these conversions. But in the world of the Arduino, this did not seem to be the case (oh, but I was wrong). So I did these conversions myself. Of course, I didn't initially set out to write these functions. Instead I did some searching and found a function that took all the components of a datetime and calculated a timestime based on the epoch, which the author seemed to think could begin at any date. But looking at the code, it seemed as if the epoch would have to be a date that ended with two zeros (1900 or 2000). Still, it was better than nothing. This is the version that ended up in my weather station client's code:

That worked okay using 2000 as the epoch. Next I tackled the problem of converting a timestamp into the little bits and pieces that go into a human-readable date. That's a trickier problem, because a lot depends on what the year is, and determining the year isn't straightforward for timestamps that fall in the final days of a year. That's because it's impossible initially to know what the effect of leap days has been on the overall date. My first stab at an algorithm seemed to work for dates falling between March 1 and December 27, but it fell apart for nearly two months of every year:

Later I found an algorithm written in Ruby that worked great once I'd migrated it to C. It was full of all sorts of arithmetic tricks and didn't make use of any loops at all. To deal with the problem of leapdays' effect on the boundaries between years, it contained a single conditional:

With both functions in place, I tested them using a wide range of dates, passing the date into one the timestamp converter and then passing the resulting timestamp back to getDateFromTimeStamp to see the human-readable result. They needed to be precisely the same. Note: the timestamps being produced by this code are different from those produced on a Unix system, which count the seconds since then beginning of 1970. My timestamps count the seconds since the beginning of 2000. It doesn't really matter, since they are only for use within the weather station client.

This afternoon Gretchen went south of High Falls to check out the new home of the farm animal sanctuary that had recently been in Willow. Meanwhile, a brief rain shower passed through, and once it was over, I made a brief firewood-gathering foray less than 80 feet southeast of where the Stick Trail crosses the Chamomile. There was a large old skeletonized oak leaning against another tree that I easily felled and then began bucking into pieces. I loaded my backpack with four thick pieces of that and three thinner pieces from another much smaller skeletonized oak tree. The resulting load was exceptionally bulky due to the dryness of the wood, straining the limits of what my bungee cords could contain. Back at the woodshed, I found the reason this load of very dry wood took up so much room: it weighed 148 pounds! I could tell it was unusually heavy as I'd approached the woodshed via the mountain goat path behind it and nearly failed in an attempt to climb one of the steps. Fortunately, there are a number of handholds that can be used in situations like this.

For linking purposes this article's URL is:

previous | next