Chrono-like clock with different epoch (from 1.1. 2000) The following will by my simple helper, that should behave just like std::chrono::system_clock but with the epoch being 1.1. 2000, that I can easily cast durations to seconds (or milliseconds or centiseconds) and store them in some records (originated from small devices).

It all started with one constexpr:

/// 1.1.2000 0:00
    static constexpr time_point&lt;system_clock&gt; epoch
      = time_point&lt;system_clock&gt;(seconds(946681200))


Which helped me to get e.g. milliseconds from 1.1.2000 like this:

duration_cast&lt;milliseconds&gt;( system_clock::now() - epoch ).count()


The problem is, that there is no contract / specification what is the epoch, but usually is 1.1. 1970.

(I have once selected 1.1. 2000 because of RTCs in units and designed the firmware to work until 1.1. 2100 when I will probably be dead already or very very old man and won't have to care... record size and amount of data transmitted was more important at the time I have designed the protocol.)

(There are some using std::chrono::system_clock and such inside namespace firda in that header)

#include "basics.hpp"
using namespace firda;

/// Clock with altered epoch
template&lt;class Clock = system_clock
  , typename Clock::rep Epoch = 946681200&gt;
  struct adapted_clock {

    using rep        = typename Clock::rep;
    using period     = typename Clock::period;
    using duration   = typename Clock::duration;
    using time_point = typename firda::time_point&lt;adapted_clock&gt;;

    static constexpr bool is_steady
      = Clock::is_steady;
    static constexpr typename Clock::time_point epoch
      = typename Clock::time_point(seconds(Epoch));

    static time_point now() {
        return time_point(Clock::now() - epoch);
    }

    static time_t to_time_t(const time_point&amp; t) {
        return Clock::to_time_t(epoch + t.time_since_epoch());
    }

    static time_point from_time_t(time_t t) {
        return time_point(Clock::from_time_t(t) - epoch);
    }
};

using y2k_clock = adapted_clock&lt;&gt;;

int main() {
    auto now1 = system_clock::now();
    auto now2 = y2k_clock::now();
    cout &lt;&lt; "now1.count: " &lt;&lt; duration_cast&lt;seconds&gt;(now1
      .time_since_epoch()).count() &lt;&lt; '\n';
    cout &lt;&lt; "now2.count: " &lt;&lt; duration_cast&lt;seconds&gt;(now2
      .time_since_epoch()).count() &lt;&lt; '\n';
    time_t time1 = system_clock::to_time_t(now1);
    time_t time2 = y2k_clock::to_time_t(now2);
    cout &lt;&lt; "time1: " &lt;&lt; std::ctime(&amp;time1) &lt;&lt; '\n';
    cout &lt;&lt; "time2: " &lt;&lt; std::ctime(&amp;time2) &lt;&lt; '\n';
}
Frankly, there isn't much to say about this class since it is simple enough and relies on another simple clock. The type alias, static members and static methods seem to all rely just like they should on the template parameter Clock so there is no problem. I believe that firda::time_point is nothing really from std::chrono::time_point os this shouldn't be a problem either.

The only remarks I have is about the template parameters: I am not sure whether defaulting Clock to std::chrono::system_clock makes sense. Is it really the default clock amongst the three standard clocks? If you think so, why. But frankly, defaulting Epoch has no sense: adapted_clock&lt;&gt; doesn't tell anything about the epoch to the user and you already provide the meaningful type alias y2k_clock (note that using the defaults is always equivalent to using y2k_clock, which makes them useless). You can't default Clock without defaulting Epoch though because you can't change the order of the template parameters.

I think that the best solution would be to leave undefaulted template parameters in adapted_clock but make y2l_clock an alias template with a possibly default Clock template parameter:

template&lt;typename Clock=std::chrono::system_clock&gt;
using y2k_clock = adapted_clock&lt;Clock, 946681200&gt;;


If you don't like this alias template solution, I would still recommend not to default the template parameters of adapted_clock but instead to write this:

using y2k_clock = adapted_clock&lt;std::chrono::system_clock, 946681200&gt;;