Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime comparison operators #24

Open
namanvs opened this issue Jun 15, 2020 · 9 comments
Open

DateTime comparison operators #24

namanvs opened this issue Jun 15, 2020 · 9 comments

Comments

@namanvs
Copy link

namanvs commented Jun 15, 2020

Can we get '<', '>', '-', '+' operator overloading for the DateTime class?

I can submit a pull request to implement this if you like.

@awickert
Copy link
Member

Please do submit a PR! I am no longer very actively maintaining this code, so community support is much appreciated.

@IowaDave
Copy link
Collaborator

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;

@awickert
Copy link
Member

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 wontfix with reason "not enough current motivation"

@namanvs
Copy link
Author

namanvs commented Aug 20, 2022

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?

@IowaDave
Copy link
Collaborator

IowaDave commented Aug 20, 2022 via email

@IowaDave
Copy link
Collaborator

@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

@namanvs
Copy link
Author

namanvs commented Sep 16, 2022

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.

@IowaDave
Copy link
Collaborator

@namanvs Welcome! I look forward to reviewing your code.

Please see my comments in the PR (#71). Thanks!

@IowaDave
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants