Time library tmElements_t validation

Hi there,

A noob question...

I got a date and time by parsing chars and I thought that checking theirs validity would be a nice QA for the parsing routine.

Could not find a function in the library to validate tmElements_t.

I actually found that setTime(makeTime(TME)); will accept "36 Jun 2018 15:28:43" and will convert it to "6 Jul 2018 15:28:43"

And that was the base to a function I wrote

boolean validateDate(tmElements_t &TME) {
  tmElements_t TMValidate;
  time_t  timeT;

  timeT = makeTime(TME);
  breakTime(timeT, TMValidate);

  return TME.Year == TMValidate.Year && TME.Month == TMValidate.Month && TME.Day == TMValidate.Day && TME.Hour == TMValidate.Hour && TME.Minute == TMValidate.Minute && TME.Second == TMValidate.Second;

It Seems to work... Any better way?


Seems like a reasonable approach to flag an illegal date/time combination of elements, but what fraction of incorrect entries would also be illegal?

Thanks for the input.

Well... I think that if the entry string date pattern will change it will produce some weird entries in many cases. Anyway that is the best I could think of and I just could not leave it with no QA at all. :roll_eyes: