One of the strange requirements I had on a project was to use the joystick button to synchronize the computer clock with an outside contact. The idea was that all of the clocks in the plant would be synchronized periodically by using a digital contact. The software would wait for the joystick button and adjust the clock to the nearest hour.

You must realize that this was long before GPS devices were common and so it seemed like a good idea at the time. This all occurred around the Y2K issue, so adjusting the clock turned out to be the most interesting part of the project. At the time I was very concerned with leap year and the year 2000, so rather than using a component I wrote a little code to calculate the next day. The code had to check if the next day was a new month (with leap year rules) and even a new year.

In researching calendar components, I learned a lot about the history of different calendars. It is very interesting but ultimately you end up wondering how historians are able to diffinitively tell when an event occurred since many countries did not accept calendar changes at the same time. For example, Russia did not adopt the Gregorian calendar until 24 January 1918 and Greece did not adopt it until 1 March 1923. You can check out the Gregorian calendar article on Wikipedia for more information.

Incidentally, the one component that I liked but did not use was Serial Day Number which converts a day into a number and allows you to perform simple mathematics and convert it back to a day. For example, to add a week you would just convert the day to a serial day number and add 7 days and convert it back to a date. Usually that is simple these days with C#, Java, and Python, but it was more complicated with C++ back then.

There is an alternative form of converting a day into a number where instead of a serial number (1, 2, 3, etc.) you convert the day into a human-ledgeable number like 20070314. The basic formula is: x = year * 10000 + month * 100 + date. The advantage of this format is that you can decode the date easily and it can be indexed quickly by a database as opposed to a native date type. The disadvantage is that you have to follow all of the normal calendar math to manipulate the number.


Comment Section

Comments are closed.