Welcome, Guest
Username: Password: Remember me

Time_point::max() blows up std::ctime()

Posts 1 to 6 of 6
6 months 1 week ago #7219
Windows 7 64 bit.
Embarcadero 10.0.1 C++ compiler. (Generating 32 bit applications.)

I'm testing out time_points (std::chrono::system_clock::time_point) using the Embarcadero 10.0.1 free C++ compiler. I have the following test code in main.cpp:

EDIT: Sorry, formatting has gone haywire here and I don;t appear to be able to fix it. :(

#include <iostream>
#include <chrono>
#include <ctime>
#include <string>
#include <exception>
using std::exception;
using std::cout;
using std::endl;
using std::string;
using std::chrono::system_clock;

// Convert a time_point to a data and time string.// Blatantly "stolen" from the "The C++ Standard Library: A Tutorial and Reference"// by Nicolai M. Josuttis.//// Thank you very much.string asString (const system_clock::time_point &tp){// Convert to system time from timepoint.std::time_t time = system_clock::to_time_t(tp);
// Trying to debug this "time_point::max()" problem!cout << "time_t time = " << time << endl;
// Convert from system time to calendar time.string dateTime("Error in ctime.");
try {dateTime = std::ctime(&time);
} catch (exception &e) {// ctime() is supposed to throw, but appears not to.cout << "EXCEPTION: '" << e.what() << '\'' << endl;return dateTime;} catch (...) {// ctime() exceptions arrive here though!cout << "I caught something, but I've no idea what!" << endl;return dateTime;}
// Lose the additional linefeed character at the end.//dateTime.resize(dateTime.size() - 1);return dateTime;}

int main(){// What is the epoch of this computer's system?system_clock::time_point tp;std:;ctime()cout << "Epoch: " << endl<< asString(tp) << endl;
// What time is it now?tp = system_clock::now();cout << "Right Now: " << endl<< asString(tp) << endl;
// What is the minimum date time of the clock?tp = system_clock::time_point::min();cout << "Minimum: " << endl<< asString(tp) << endl;
// What is the maximum date time of the clock?tp = system_clock::time_point::max();cout << "Maximum: " << endl<< asString(tp) << endl;
}


Everything works fine until I get to checking time_point::max() which throws. It seems that time_point::max() returns a negative number when converted to the std::time_t, as the debuugging output in the following example shows:


Epoch:time_t time = 0Thu Jan  1 00:00:00 1970
Right Now:time_t time = 1489668013Thu Mar 16 13:40:13 2017
Minimum:time_t time = 1080764955Wed Mar 31 20:29:15 2004
Maximum:time_t time = -1080764955I caught something, but I've no idea what!Error in ctime.

I can live without knowing what the max() time_point will be, in date and time formats, but it could be a bug/feature that affects someone who does need to know.
Any advice, pointers to solutions etc gratefully received. I've done the google thing and come up blanks - as did a search of these forums.
Many thanks.

Cheers,
Norm.
Last Edit: 6 months 1 week ago by NormanDunbar.
Log in to reply.
6 months 1 week ago #7231
Hi NormanDunbar,
> It seems that time_point::max() returns a negative number when converted to the std::time_t, as the debuugging output in the following example shows:
>
Maximum:time_t time = -1080764955I caught something, but I've no idea what!Error in ctime.

You take time and effort.
https://quality.embarcadero.com/
I'd like you to report it to the above URL.
Certainly the possibility of a bug is high
haruyuki
Log in to reply.
6 months 1 week ago #7240
Hi Haruyuki,
I tried to report this as a bug at the URL you supplied. Unfortunately it refuses to let me login with my EDN credentials. I simply can't get past the log screen. :-(
I did check that my login credentials were correct on EDN, no problems there. There was a link to qc.embarcadero.com on EDN, which I also tried, but no joy, it timed out.

Cheers,
Norm.
Log in to reply.
6 months 6 days ago #7249
I want you to create an EDN account and a new one.
So, can you try again?
Log in to reply.
6 months 6 days ago #7252
I have created a new account, with some trouble as it kept rejecting me as "already existing" - so I now have a pseudonym!

The issue has been logged in quality as https://quality.embarcadero.com/browse/AP-205.

Cheers,
Norm.
Log in to reply.
6 months 5 days ago #7258
thanks NormanDunbar,

In addition, please report again if a problem is found.
Log in to reply.
Moderators: @aprilanne