// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.

#ifndef tools_s2time
#define tools_s2time

#include <ctime>
#include <string>
#include <cstdio> //sscanf

namespace tools {

inline bool s2time(const std::string& a_string,time_t& a_time) {
  int yy, _mm, dd, hh, mi, ss;
  if(::sscanf(a_string.c_str(),
              "%d-%d-%d %d:%d:%d",
              &yy,&_mm,&dd,&hh,&mi,&ss)!=6) {a_time = 0;return false;}
  struct tm tp;
  tp.tm_year  = yy-1900;
  tp.tm_mon   = _mm-1;
  tp.tm_mday  = dd;
  tp.tm_hour  = hh;
  tp.tm_min   = mi;
  tp.tm_sec   = ss;
  tp.tm_isdst = 0;
  a_time  = ::mktime(&tp);
  return true;
}

}

#endif
