Painless handling of dates, times, events and calendars on embedded systems

Painless handling of dates, times, events and calendars on embedded systems

I do not enjoy dealing with the vagaries of calendar dates and times… Actually, I pretty much hate it.

It’s mostly because I have little patience for arbitrary rules and convoluted systems, and anything as old as the notion of date-times is always filled with historical cruft: half-baked rules, a bunch of incompatible, random-looking, bases (60 seconds in a minute, 24 hours in a day) and a whole lotta exceptions (months have 30 or 31 days. and don’t get me started on February).

Hoping for a sensible date/time system is like trying to get everyone to speak esperanto… the best answer you can expect is “Hm, yes, you have very logical and convincing arguments. But not today“.  So that’s how it works and if you want to interact with people and the outside world, you’re bound to eventually need to deal with times and dates.

So what is a programmer to do when faced with such a distasteful but unavoidable task?  Spend days on end working on the problem while writing a library, of course, such that you will never have to think about it too much again!

And then share that library, so we can all spend our time dealing with newer and more interesting problems :)

So that’s where we are now: Chronos, a low-footprint library that allows you to handle date-times, setup event calendars and find points of interest in your schedules, has been released and documented.

You can do the obvious with Chronos, like get a DateTime object for “in 15 minutes”:

  Chronos::DateTime in15 = Chronos::DateTime::now() + Chronos::Span::Minutes(15);

More interestingly, you can ask Chronos things such as:

  • give me a DateTime for next Saturday
  • How many days until my birthday?
  • Setup a recurring event, 2 hours long, every day (or week, or month or year)
  • When is my next monthly Coucil of Elders meeting?
  • List my previous 10 yoga classes

etc.

And the library works hard to spare your embedded system’s memory: a calendar with 10 repeating events of any type takes up all of 415 bytes of RAM.

Check out Chronos and see what it can do for you. I hope my efforts will make your projects more powerful and easier to create.  And do let me know if and how you wind up using the library!