CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/OnlineDB/EcalCondDB/src/DateHandler.cc

Go to the documentation of this file.
00001 #include "OnlineDB/Oracle/interface/Oracle.h"
00002 #include "OnlineDB/EcalCondDB/interface/Tm.h"
00003 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
00004 
00005 using namespace oracle::occi;
00006 
00007 DateHandler::DateHandler(Environment* env, Connection* conn)
00008 {
00009   m_env = env;
00010   m_conn = conn;
00011 
00012   PLUS_INF_DATE = maxDate();
00013   PLUS_INF = dateToTm(PLUS_INF_DATE);
00014   NEG_INF_DATE = minDate();
00015   NEG_INF = dateToTm(NEG_INF_DATE);
00016 }
00017 
00018 DateHandler::~DateHandler() {}
00019 
00020 Date DateHandler::tmToDate(const Tm& inTm) const
00021 {
00022   if (inTm.isNull()) {
00023     return Date();
00024   } else {
00025     struct tm ctm = inTm.c_tm();
00026     return Date(m_env, ctm.tm_year + 1900, ctm.tm_mon + 1, ctm.tm_mday, 
00027                 ctm.tm_hour, ctm.tm_min, ctm.tm_sec);
00028   }
00029 }
00030 
00031 Tm DateHandler::dateToTm(Date& date) const
00032 {
00033   if (date.isNull()) {
00034     return Tm();
00035   }
00036 
00037   int year;
00038   unsigned int mon; // month
00039   unsigned int mday; // day of month
00040   unsigned int hour;
00041   unsigned int min; // minute
00042   unsigned int sec; // second
00043 
00044   date.getDate(year, mon, mday, hour, min, sec);
00045 
00046   // work on the provided tm
00047   struct tm retTm;
00048   retTm.tm_year = year - 1900;
00049   retTm.tm_mon = mon - 1;
00050   retTm.tm_mday = mday;
00051   retTm.tm_hour = hour;
00052   retTm.tm_min = min;
00053   retTm.tm_sec = sec;
00054   retTm.tm_isdst = 0;
00055   retTm.tm_wday = 0;
00056   retTm.tm_yday = 0;
00057 
00058   mktime(&retTm);  // calculates tm_wday and tm_yday
00059 
00060   return Tm(&retTm);
00061 }