RTClib icon indicating copy to clipboard operation
RTClib copied to clipboard

Constexpr DateTime/TimeSpan constructors

Open maxbla opened this issue 4 years ago • 2 comments

  • Arduino board: All; N/a

  • Arduino IDE version (found in Arduino -> About Arduino menu): N/a

Feature Request: constexpr constructors for DateTime / TimeSpan

This would allow me to generate helpful error messages at compile time for DateTimes/TimeSpans that are invalid in a certain context using static_assert. Previously I have used run-time checks with Serial.println, but this method only catches mistakes if developers are looking at their serial console.

I think this is as simple as marking the constructors constexpr, but I might be missing something

maxbla avatar Mar 10 '21 05:03 maxbla

After some investigation, most TimeSpan constructors can be made constexpr, but most DateTime constructors can't without C++14 constexpr features (Arduino currently uses C++11 by default).

maxbla avatar Mar 14 '21 00:03 maxbla

If Arduino ever makes C++14 the default, This stack overflow question has some code that might be worth borrowing from.

maxbla avatar Mar 14 '21 08:03 maxbla