Date and time

I've got a reasonably small date-time library working in Picobit. I started off with SRFI-19, but found it's reference implementation used floating point numbers for Julian day, and used Julian day to calculate conversions between UTC and the Gregorian calendar. Trying to figure out if I could change this to integer arithmetic didn't seem that easy.

Instead, I found a ground up integer method in Joda-time, and used that instead. It's calculation is incredibly easy to understand, once you get over the fact that it's pulled to pieces into several subclasses and helpers, to the extent that you wonder why everyone doesn't do it the same way. I got to simplify it even more, because Picobit gives you more latitude with arbitrary precision.

The result is fairly like SRFI-19 but ignores leap seconds, and therefore the distinction between TAI and UTC, replacing them with time-real. This makes all the more sense given that most microcontroller projects will probably want to start with calendar time from a chip like the DS1309, as found in TinyRTC modules and generate UTC, and these types of chips don't include a table of leap seconds (or for that matter count seconds).

I've removed all the formatting code because there doesn't seem any reason for a micro controller to be able to format the date and time into a string, and as implemented by the reference implementation, it just generates too much code to be feasible. If I decide I want any kind of formatting, I'm probably going to need to devise some compiler mechanism.

It's actually taken me ages to get here, because a while back I broke the arbitrary precision numbers to get bitwise-and and greater precision when converting to C integers. There's no way I could us 24 bit integers to implement a reasonable time library, so I went back and fixed that first.

I wanted to add this functionality so I could calculate the number of seconds from midday, which in turn I can use to estimate daylight. I guess I'll also want to add support for daylight savings. In turn, I need an integer approximation for sine.

Popular posts from this blog

3D Printer ramblings

Balance Bot V2

Robot arm