#include "gscUtils.hxx" #include #include int gscUtils::EncodeTime(const char *date_yyyymmdd, const char *time_hhmmss){ tm timeDecoder; char Dum[50]; strncpy(Dum,date_yyyymmdd,4); strncpy(Dum+4,"\n",1); //std::cout << Dum << std::endl; timeDecoder.tm_year = atoi(Dum); //std::cout << atoi(Dum) << std::endl; timeDecoder.tm_year -= 1900; strncpy(Dum,date_yyyymmdd+5,2); strncpy(Dum+2,"\n",1); timeDecoder.tm_mon = atoi(Dum); timeDecoder.tm_mon--; strncpy(Dum,date_yyyymmdd+8,2); strncpy(Dum+2,"\n",1); timeDecoder.tm_mday = atoi(Dum); strncpy(Dum,time_hhmmss,2); strncpy(Dum+2,"\n",1); timeDecoder.tm_hour = atoi(Dum); strncpy(Dum,time_hhmmss+3,2); strncpy(Dum+2,"\n",1); timeDecoder.tm_min = atoi(Dum); strncpy(Dum,time_hhmmss+6,2); strncpy(Dum+2,"\n",1); timeDecoder.tm_sec = atoi(Dum); timeDecoder.tm_isdst=1; time_t checkTime = mktime(&timeDecoder); if(checkTime != -1){ int requested_time = checkTime; return requested_time; } else{ std::cerr << "Problem decoding date and time: " << date_yyyymmdd << " " << time_hhmmss << std::endl; std::cerr << "Usage: FgdFEBTemperature.exe or FgdFEBTemperature.exe yyyy-mm-dd hh:mm:ss filename or variations" << std::endl; exit(0); return -1; } } int gscUtils::GetEncodedCurrentTime(){ time_t rawtime; struct tm *timeinfo; char date_yyyymmdd[80]; char time_hhmmss[80]; time ( &rawtime ); timeinfo = localtime ( &rawtime ); strftime(date_yyyymmdd,80,"%Y-%m-%d_%H:%M:%S",timeinfo); strftime(time_hhmmss,80,"%H:%M:%S",timeinfo); return EncodeTime(date_yyyymmdd,time_hhmmss); } int gscUtils::GetEncodedPreviousWeek(){ return GetEncodedCurrentTime() - 60*60*24*7; //seg*min*hours*days in a week }