print minimum/maximum time of this system clock - by ioni

Status : 


Sign in
to vote
ID 775105 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 12/24/2012 11:14:45 PM
Access Restriction Public


print minimum/maximum time of this system clock always return empty string
Sign in to post a comment.
Posted by Deon [MSFT] on 4/29/2014 at 12:31 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from:
Posted by Stephan [MSFT] on 2/11/2013 at 4:49 PM

Thanks for reporting this bug. We've fixed it, and the fix will be available
in VC12. (Our version numbers are: VC8 = VS 2005, VC9 = VS 2008, VC10 = VS
2010, VC11 = VS 2012.)

The bug we fixed was not the bug you reported. Here is a detailed test case,
compiled with VC11:

C:\Temp>type meow.cpp
#include <time.h>
#include <chrono>
#include <iostream>
#include <ostream>
using namespace std;
using namespace std::chrono;

void print(const char * const name, const system_clock::time_point& tp) {
    cout << "[" << name << "]" << endl;

    cout << "tp.time_since_epoch().count(): " << tp.time_since_epoch().count(
) << endl;

    cout << "system_clock::period: " << system_clock::period::num << "/" <<
system_clock::period::den << endl;

    const time_t t = system_clock::to_time_t(tp);

    cout << "system_clock::to_time_t(tp): " << t << endl;

    const char * const s = ctime(&t);

    if (s) {
        cout << "ctime(&t): " << s;
    } else {
        cout << "ctime(&t): null" << endl;

    cout << endl;

int main() {
    print("system_clock::now()", system_clock::now());
    print("system_clock::time_point::min()", system_clock::time_point::min());
    print("system_clock::time_point::max()", system_clock::time_point::max());

C:\Temp>cl /EHsc /nologo /W4 /MTd /wd4996 meow.cpp

tp.time_since_epoch().count(): 13606284605813155
system_clock::period: 1/10000000
system_clock::to_time_t(tp): 1360628461
ctime(&t): Mon Feb 11 16:21:01 2013

tp.time_since_epoch().count(): -9223372036854775808
system_clock::period: 1/10000000
system_clock::to_time_t(tp): -922337203684
ctime(&t): null

tp.time_since_epoch().count(): 9223372036854775807
system_clock::period: 1/10000000
system_clock::to_time_t(tp): -922337203684
ctime(&t): null

N3485 [time.clock.system] says that system_clock::time_point is a
typedef for time_point<system_clock>.

20.11.6 [time.point] specifies "template <class Clock, class Duration =
typename Clock::duration> class time_point". [time.clock.system] says that system_clock::duration is a typedef
for duration<system_clock::rep, system_clock::period>, where system_clock::
rep is unspecified (but must be signed) and system_clock::period is an
unspecified ratio. In our implementation, system_clock::rep is long long, and
you can see the period above (10 million ticks per second). [time.point.special] requires time_point::min/max() to return
time_point(duration::min/max()). [time.duration.special] requires duration::min/max() to return
duration(duration_values<rep>::min/max()). [time.traits.duration_values] requires duration_values<Rep>::min/max
() to return numeric_limits<Rep>::lowest/max().

Therefore, the values printed for tp.time_since_epoch().count() above (-2^63
and 2^63 - 1) are correct.

The bug we fixed was that for system_clock::time_point::max(), system_clock::
to_time_t(tp) returned a negative value. This was caused by code within
to_time_t() that attempted to perform rounding, but triggered integer
overflow when given an enormous input. [time.clock.system]/3 says "
It is implementation defined whether values are rounded or truncated to the
required precision.", so we changed to_time_t() to truncate, making integer
overflow impossible.

However, ctime(&t) still returns null for system_clock::time_point::min/max()
. Remember that, given our choice of long long for the representation type,
min/max() are required to be -2^63 and 2^63 - 1 ticks, or 922 billion seconds
(29,227 years) before/after the epoch. As documented at
com/en-us/library/59w5xcdy.aspx , our implementation of ctime() returns null
for years before 1970 or after 3000.

Note: Connect doesn't notify me about comments. If you have any further
questions, please E-mail me.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
Posted by Macy [MSFT] on 12/25/2012 at 1:00 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Macy [MSFT] on 12/24/2012 at 11:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(