std::gmtime
is failing for me when I pass it the max possible std::time_t
. See the following test:
std::cout << "sizeof(std::time_t): " << sizeof(std::time_t) << '\n'
<< "sizeof(long long): " << sizeof(long long) << '\n'
<< "sizeof(unsigned int): " << sizeof(unsigned int) << "\n\n";
auto testgmtime = [](std::time_t time)
{
std::tm* ptm = std::gmtime(&time);
std::cout << (ptm ? "succeeded\n" : "failed\n");
};
testgmtime(std::numeric_limits<std::time_t>::max());
testgmtime(std::numeric_limits<long long>::max());
testgmtime(std::numeric_limits<long long>::max()-1);
testgmtime(static_cast<std::time_t>(std::numeric_limits<unsigned int>::max())*2);
testgmtime(std::numeric_limits<int>::max());
Output:
sizeof(std::time_t): 8
sizeof(long long): 8
sizeof(unsigned int): 4
failed
failed
failed
succeeded
succeeded
I'm using VS2012. Is there a standard limit I'm not seeing or is this VS being crappy? What alternative can I use that works?