DS3231
DS3231 copied to clipboard
DateTime comparison operators
Can we get '<', '>', '-', '+' operator overloading for the DateTime class?
I can submit a pull request to implement this if you like.
Please do submit a PR! I am no longer very actively maintaining this code, so community support is much appreciated.
Overloading might be desirable. If @namanvs would submit a PR I would be happy to review it.
It may be worth noting, however, that such comparisons and arithmetic can be done presently without overloading. The approach would be to calculate a difference in seconds, taking advantage of the DateTime::unixtime() method.
Code segment:
DateTime A(); // assume initiated properly
DateTime B(); // assume initiated properly
uint32_t a = A.unixtime();
uint32_t b = B.unixtime
if (a > b) { // A is after B }
uint32_t diff = a - b;
Good point @IowaDave.
I don't have need for this overloading so won't be dev'ing it. How about this as a plan?
- If we hear from @namanvs soon-ish about creating a PR, great
- Otherwise, we close this as
wontfixwith reason "not enough current motivation"
Hi @awickert and @IowaDave, sorry, I've been travelling but I would be happy to write these operators. I will need about 10 days to get back up to speed and have something ready, but I plan on implementing the following operators: '<', '>', '+', and '-'. I'll probably use @awickert 's suggested strategy but wrap it up into the operators for convenience. I am toying with a modulo operator to return the remainder between 2 operands in the next-smallest unit:
DateTime a % DateTime::DAYS returns number of hours in the remainder.
Would this seem useful?
I will wait to complete and PR my documentation on DateTime until after the proposed enhancements to DateTime are in place.
Thanks!
On Fri, Aug 19, 2022 at 7:03 PM Naman Shah @.***> wrote:
Hi @awickert https://github.com/awickert and @IowaDave https://github.com/IowaDave, sorry, I've been travelling but I would be happy to write these operators. I will need about 10 days to get back up to speed and have something ready, but I plan on implementing the following operators: '<', '>', '+', and '-'. I'll probably use @awickert https://github.com/awickert 's suggested strategy but wrap it up into the operators for convenience. I am toying with a modulo operator to return the remainder between 2 operands in the next-smallest unit:
DateTime a % DateTime::DAYS returns number of hours in the remainder.
Would this seem useful?
— Reply to this email directly, view it on GitHub https://github.com/NorthernWidget/DS3231/issues/24#issuecomment-1221179878, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIOVVUBUWKW4I4XMDP6ACMDV2AOGBANCNFSM4N6FTSMA . You are receiving this because you were mentioned.Message ID: @.***>
@namanvs , @awickert , I have added the DateTime documentation to the master branch of this repo. In the near future, PR #70 may add an example program that uses a DateTime calculation to advance the time values of an alarm.
I'll look forward to viewing that PR you mentioned, if you choose to offer it.
Thank you sincerely,
David
I have submitted a PR. This is actually the first time I'm contributing to code on Github. Open to feedback and willing to make improvements where identified.
@namanvs Welcome! I look forward to reviewing your code.
Please see my comments in the PR (#71). Thanks!
Changed the label to Enhancement because that is really what @namanvs is proposing. Leaving this Issue open pending resolution of his PR #71.
cc: @awickert