mktime
return is as follow :
Time since epoch as a
std::time_t
object on success or-1
if time cannot be represented as astd::time_t
object.
std::time_t
is defined as follow :
Arithmetic type capable of representing times.
Although not defined, this is almost always a integral value holding the number of seconds (not counting leap seconds) since
00:00, Jan 1 1970 UTC
, corresponding to POSIX time.
So 31/12/1920 cannot be represented into a std::time_t
as it is before the epoch.
As for the other invalid dates that are reported as valid, mktime
also states :
The values in [the parameter] are permitted to be outside their normal ranges.
Here is the example taken from cppreference :
#include <iostream>
#include <iomanip>
#include <ctime>
int main()
{
std::time_t t = std::time(NULL);
std::tm tm = *std::localtime(&t);
std::cout << "Today is " << std::put_time(&tm, "%c %Z") <<'\n';
tm.tm_mon -= 100; // tm_mon is now outside its normal range
std::mktime(&tm);
std::cout << "100 months ago was " << std::put_time(&tm, "%c %Z") << '\n';
}
Output is :
Today is Wed Dec 28 09:56:10 2011 EST
100 months ago was Thu Aug 28 10:56:10 2003 EDT