Please note that this is asking a question about constructors, not about classes which handle time.
Suppose I have a class like this:
- have the constructor throw an exception, and have handlers in the calling function to handle it.
Yes. Design by Contract and leave the precondition checking on, and in case of failure, throw an exception. No invalid times anymore.
- have a flag in the class and set it to true only if the values are acceptable by the constructor, and have the program check the flag immediately after construction.
Maybe. Acceptable in complex cases but again, throw if your checking fails.
- have a separate (probably static) function to call to check the input parameters immediately before calling the constructor.
Maybe. This is about telling whether input data are correct or not, and may be useful if telling that is nontrivial, but see above for how to react in case of invalid data.
- redesign the class so that it can be constructed from any input parameters.
No. You would basically defer the problem.