title: How to safely clock_cast days?
body: <p>I'm using <a href="https://github.com/HowardHinnant/date" rel="nofollow noreferrer">HowardHinnant/date</a> in lieu of the new C++20 calendar/timezone facilities that are not yet available in Clang/GCC. My question applies equally to both implementations: How do I safely <code>clock_cast</code> <code>time_point</code>s having <code>days</code> duration?</p>
  <p>When I try:</p>
  <pre class="lang-cpp prettyprint-override"><code>using namespace date; // or using std::chrono in C++20
  tai_time&lt;days&gt; tai{days{42}};
  sys_days sys = clock_cast&lt;std::chrono::system_clock&gt;(tai);
  </code></pre>
  <p>I get a &quot;no viable conversion&quot; error for the last statement. It turns out the result uses a duration that is <code>common_type&lt;days, seconds&gt;</code>, which comes from <code>utc_clock::to_sys()</code> that's used in the conversion. The common duration type is <code>std::chrono::seconds</code>, so it's normal that it can't be directly converted to a <code>days</code> duration.</p>
  <p>I can get it to compile if I use an explicit <code>duration_cast</code>:</p>
  <pre class="lang-cpp prettyprint-override"><code>using namespace date; // or using std::chrono in C++20
  tai_time&lt;days&gt; tai{days{42}};
  auto casted = clock_cast&lt;std::chrono::system_clock&gt;(tai);
  sys_days sys{std::chrono::duration_cast&lt;days&gt;(casted.time_since_epoch())};
  </code></pre>
  <p>... but I'm worried that the result might by off by a day due to the truncation (especially for dates preceding the epoch). Is this the correct way to do what I'm trying to do? Should I be using <code>floor</code> instead of <code>duration_cast</code>?</p>
  <p>Why is there even a <code>std::common_type_t&lt;Duration, std::chrono::seconds&gt;</code> in <code>utc_clock::to_sys()</code> anyway? Shouldn't it simply return the same duration type?</p>