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).
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:feedback
previous | next