mikaelpatel/Cosa — pull request #249 by SlashDevin (2014-11-04 04:46:21+00:00)
Title: time_t support for multiple epochs

By making `epoch_year` et al static members, different epochs can be selected at run time. This allows NTP to do its calculations WRT the NTP epoch, while all other Cosa examples run on a more-efficient epoch. NTP sketches could be optimized if they were to calculate a `clock_t` offset (once) and then use that to offset the NTP clock_t into the RTC `clock_t`. In fact, any number of epochs could be used in a sketch as long as the `clock_t` offsets are computed.

I think this may address the concern about the RTC epoch -- now you can pick whatever you want and simply offset it into other epochs as needed.

I also added a `time_t::use_fastest_epoch` that sets the `epoch_year` to the *currrent* year, as defined by the preprocessor predefined macro `__DATE__`. Conversion times are now even better, about 4 or 5 times faster than the original:
* time_t(clock,zone): 130uS (new) vs. 480uS (old)
* operator clock_t(): 48uS (new) vs. 190uS (old)

The CosaTime log shows those measurements, as well as the impact of running on other epochs.

BTW, the new `time_t::parse` could eliminate some code in the xxxCommands where they parse dates. A minor bug: I noticed that some of those files allow 60 minutes or seconds to be accepted as a valid time (should reject `> 59`). You may not want CosaAlarm.ino... maybe that's an old version?

Regards,
Devin