#include <ctype.h>
/* makeTimestamp by Kiasyn */
/* Will convert a string in format: #m#d#h#m to a timestamp.
Can be used in:
- Banning, doing a current_time + makeTimestamp(argument) will create
a future timestamp of whatever */
time_t makeTimestamp( char *str )
{
int number = 0;
time_t timestamp = 0;
for ( int i = 0; i < strlen(str); i++ )
{
if ( isdigit(str[i]) )
{
number = number * 10 + str[i] - '0';
continue;
}
else if ( str[i] == 'm' )
timestamp += number*2592000; // 2592000 = 1 month
else if ( str[i] == 'd' )
timestamp += number*86400; // 86400 == 24 hours
else if ( str[i] == 'h' )
timestamp += number*3600; // 3600 = 1 hour
else if ( str[i] == 'm' )
timestamp += number*60; // 60 = 1 minute
else if ( isspace(str[i]) )
continue;
number = 0;
}
bug( "makeTimestamp: %d", (int)timestamp );
return timestamp;
}