Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/s2time is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_s2time
0005 #define tools_s2time
0006 
0007 #include <ctime>
0008 #include <string>
0009 #include <cstdio> //sscanf
0010 
0011 namespace tools {
0012 
0013 inline bool s2time(const std::string& a_string,time_t& a_time) {
0014   int yy, _mm, dd, hh, mi, ss;
0015   if(::sscanf(a_string.c_str(),
0016               "%d-%d-%d %d:%d:%d",
0017               &yy,&_mm,&dd,&hh,&mi,&ss)!=6) {a_time = 0;return false;}
0018   struct tm tp;
0019   tp.tm_year  = yy-1900;
0020   tp.tm_mon   = _mm-1;
0021   tp.tm_mday  = dd;
0022   tp.tm_hour  = hh;
0023   tp.tm_min   = mi;
0024   tp.tm_sec   = ss;
0025   tp.tm_isdst = 0;
0026   a_time  = ::mktime(&tp);
0027   return true;
0028 }
0029 
0030 inline bool time2s(std::string& a_s) {
0031   time_t d;
0032   if(::time(&d)==(time_t)-1) {a_s.clear();return false;}
0033   char* _cstr = ::ctime(&d);
0034   _cstr[24] = '\0';
0035   a_s = _cstr;
0036   return true;
0037 }
0038 
0039 }
0040 
0041 #endif