I think you are right on track because your code has pretty much the same interface as as the Standard Library header <chrono>. Just replace all your classes with #include <chrono>, your static_cast to duration_cast and .value to count() and you are all set:
#include <iostream> #include <chrono> int main() { using namespace std::chrono; minutes m{60}; seconds s{3600}; hours h{1}; std::cout << (duration_cast<seconds>(m).count() == s.count()); std::cout << (duration_cast<seconds>(h).count() == s.count()); std::cout << (duration_cast<minutes>(s).count() == m.count()); std::cout << (duration_cast<minutes>(h).count() == m.count()); std::cout << (duration_cast<hours>(s).count() == h.count()); std::cout << (duration_cast<hours>(m).count() == h.count()); // Bonus std::cout << (s == m) << (m == h); }
Live Example.
The <chrono> implementation is a lot easier than your classes: it consists of a single class template
template<class Rep, class Period> class duration<Rep, Period = std::ratio<1>>;
The Rep parameter is a signed integer that contains the count(), and the std::ratio is used to convert without loss of precision. You can also define your own types day, week or year this way. As you can so from my code example, you don't have to convert types to prove equality, just use == directly on the objects. duration_cast is only necessary to print stuff in different units, not for computations.