if( 0 != mkdir( filename.c_str(), 0755 ) ) {
if( EEXIST != errno ) {
- throw std::runtime_error("Storage location could not be determined");
+ throw std::runtime_error( "Storage location could not be determined" );
}
//! \FIXME: Check this is a directory
return std::pair<bool, time_t>( false, 0 );
}
- std::tm t;
+ std::tm t = {};
t.tm_sec = 0;
t.tm_min = 0;
t.tm_hour = 0;
- t.tm_year = std::stoi( date.substr( 0, 4 ) ) - 1900;
- t.tm_mon = std::stoi( date.substr( 5, 2 ) ) - 1;
t.tm_mday = std::stoi( date.substr( 8, 2 ) );
- t.tm_wday = 0; /* Day of the week (0-6, Sunday = 0) */
- t.tm_yday = 0; /* Day in the year (0-365, 1 Jan = 0) */
- t.tm_isdst = 0; /* Daylight saving time */
+ t.tm_mon = std::stoi( date.substr( 5, 2 ) ) - 1;
+ t.tm_year = std::stoi( date.substr( 0, 4 ) ) - 1900;
setenv( "TZ", "UTC", 1 );
tzset();
}
std::pair<bool, time_t> addMonths( std::time_t t, int32_t count ) {
- std::tm* parsed = gmtime( &t );
+ std::tm *parsed = gmtime( &t );
if( !parsed || count <= 0 || count > 24 ) { // FIXED MAX-Validity-Length
return std::pair<bool, time_t>( false, 0 );
try {
size_t end = 0;
- int num = std::stoi( date.substr( 0, date.size() - 1 ) , &end );
+ int num = std::stoi( date.substr( 0, date.size() - 1 ), &end );
if( end != date.size() - 1 ) {
return std::pair<bool, time_t>( false, 0 );
}
}
-std::unique_ptr<std::ofstream> openLogfile( const std::string &name ) {
+std::unique_ptr<std::ofstream> openLogfile( const std::string& name ) {
struct stat buffer;
std::string tname = name;
int ctr = 2;
auto res = std::make_unique<std::ofstream>( tname );
if( ! res->good() ) {
- throw std::runtime_error( std::string("Failed to open file for logging: " ) + name );
+ throw std::runtime_error( std::string( "Failed to open file for logging: " ) + name );
}
return res;
}
-std::string timestamp(){
+std::string timestamp() {
time_t c_time;
+
if( time( &c_time ) == -1 ) {
throw std::runtime_error( "Error while fetching time?" );
}
+
return std::to_string( c_time );
}