00001 /*************************************************************************** 00002 * Copyright (c) Riegel <juergen.riegel@web.de> * 00003 * * 00004 * This file is part of the FreeCAD CAx development system. * 00005 * * 00006 * This library is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Library General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU Library General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Library General Public * 00017 * License along with this library; see the file COPYING.LIB. If not, * 00018 * write to the Free Software Foundation, Inc., 59 Temple Place, * 00019 * Suite 330, Boston, MA 02111-1307, USA * 00020 * * 00021 ***************************************************************************/ 00022 00023 00024 #include "PreCompiled.h" 00025 00026 #ifndef _PreComp_ 00027 # include <sstream> 00028 #endif 00029 00030 #include "TimeInfo.h" 00031 00032 00033 using namespace Base; 00034 00035 00040 TimeInfo::TimeInfo() 00041 { 00042 setCurrent(); 00043 } 00044 00049 TimeInfo::~TimeInfo() 00050 { 00051 } 00052 00053 00054 //************************************************************************** 00055 // separator for other implemetation aspects 00056 00057 void TimeInfo::setCurrent(void) 00058 { 00059 #if defined (_MSC_VER) 00060 _ftime( &timebuffer ); 00061 #elif defined(__GNUC__) 00062 ftime( &timebuffer ); 00063 #endif 00064 } 00065 00066 void TimeInfo::setTime_t (uint64_t seconds) 00067 { 00068 timebuffer.time = seconds; 00069 } 00070 00071 const char* TimeInfo::currentDateTimeString() 00072 { 00073 struct tm* systime; 00074 time_t sec; 00075 00076 time(&sec); 00077 systime = localtime(&sec); 00078 00079 const char* dt = asctime(systime); 00080 return dt; 00081 } 00082 00083 std::string TimeInfo::diffTime(const TimeInfo &timeStart,const TimeInfo &timeEnd ) 00084 { 00085 std::stringstream str; 00086 str << diffTimeF(timeStart,timeEnd); 00087 return str.str(); 00088 } 00089 00090 float TimeInfo::diffTimeF(const TimeInfo &timeStart,const TimeInfo &timeEnd ) 00091 { 00092 if(timeStart.getSeconds()==timeEnd.getSeconds()) 00093 return float(timeEnd.getMiliseconds())/1000.0 - float(timeStart.getMiliseconds())/1000.0; 00094 else 00095 return float(timeEnd.getSeconds()-timeStart.getSeconds()-1)+float((1000-timeStart.getMiliseconds())/1000.0)+float(timeEnd.getMiliseconds())/1000.0; 00096 } 00097 00098 TimeInfo TimeInfo::null() 00099 { 00100 TimeInfo ti; 00101 ti.timebuffer.time = 0; 00102 ti.timebuffer.millitm = 0; 00103 return ti; 00104 } 00105 00106 bool TimeInfo::isNull() const 00107 { 00108 return (*this) == TimeInfo::null(); 00109 }