1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
class CMemoTime //:// public CWnd
{
// Construction
public:
CMemoTime()
{} ;
// Attributes
protected :
string m_pathMemoTime ;
// Implementation
public:
~CMemoTime()
{};
void InitMemoTime(/// chemin du fichier de mémorisation
string _path)
{ m_pathMemoTime = _path ; } ;
void MemoTimeCreateRef() ;
void GetCurDateTime(int & _year, int & _month, int & _day, int & _hour, int & _minutes, int & _seconds);
bool GetMemoTime(int & _year, int & _month, int & _day, int & _hour, int & _minutes, int & _seconds);
bool TestIfInTime(int _hoursMax, int _minutesMax, int _secondsMax) ;
void CalcTimeInSec(int _hours, int _mn, int _s, int & _timeRes) ;
void CalcEcart_TimeInSec(int _hoursA, int _mnA, int _sA,
int _hoursB, int _mnB, int _sB,int & _timeRes) ;
void CalcEcart_DayTimeInSec(int _dayA, int _hoursA, int _mnA, int _sA,
int _dayB, int _hoursB, int _mnB, int _sB,
int & _timeRes) ;
bool isYearBis(int _year);
void CalcNbDayInMonth(int _year, int _month, int & _day);
void CalcEcart_MonthDayTimeInSec(int _yearA, int _monthA, int _dayA, int _hoursA, int _mnA, int _sA,
int _monthB, int _dayB, int _hoursB, int _mnB, int _sB,
int & _timeRes);
void CalcEcart_YearMonthDayTimeInSec(int _yearA, int _monthA, int _dayA, int _hoursA, int _mnA, int _sA,
int _yearB, int _monthB, int _dayB, int _hoursB, int _mnB, int _sB,
int & _timeRes) ;
};
inline
void CMemoTime::MemoTimeCreateRef()
{
if (m_pathMemoTime.empty() != 0)
return ;
//--------------------------
// mémorisation de l'heure
ofstream fHorloge ;
fHorloge.open(m_pathMemoTime.c_str()) ;
if (fHorloge.is_open() != 0)
{
setlocale( LC_ALL, "" );
CTime theTime = CTime::GetCurrentTime();
fHorloge << theTime.GetDay() << " / " << theTime.GetMonth() << " / " << theTime.GetYear() << " - " << theTime.GetHour() << " : " << theTime.GetMinute() << " : " << theTime.GetSecond() << endl ;
fHorloge.close() ;
}
}
inline
void CMemoTime::GetCurDateTime(int & _year, int & _month, int & _day, int & _hour, int & _minutes, int & _seconds)
{
setlocale( LC_ALL, "" );
CTime theTime = CTime::GetCurrentTime();
_year = theTime.GetYear() ;
_month = theTime.GetMonth() ;
_day = theTime.GetDay() ;
_hour = theTime.GetHour() ;
_minutes = theTime.GetMinute() ;
_seconds = theTime.GetSecond() ;
}
inline
bool CMemoTime::GetMemoTime(int & _year, int & _month, int & _day, int & _hour, int & _minutes, int & _seconds)
{
ifstream fHorloge ;
fHorloge.open(m_pathMemoTime.c_str()) ;
if (fHorloge.is_open() == 0)
return false;
while (!fHorloge.eof())
{
string line ;
std::getline(fHorloge, line) ;
if (line.empty() != true)
{
string tmp ;
stringstream strLine ;
strLine << line ;
strLine >>_day >> tmp >> _month >> tmp >> _year >> tmp >> _hour >> tmp >> _minutes >> tmp >> _seconds ;
break ;
}
}
fHorloge.close() ;
return true ;
}
inline
bool CMemoTime::TestIfInTime(int _hoursMax, int _minutesMax, int _secondsMax)
{
int yearCur, monthCur, dayCur, hourCur, minutesCur, secondsCur ;
int year, month, day, hour, minutes, seconds ;
if (GetMemoTime(year, month, day, hour, minutes, seconds) != true)
return false ;
GetCurDateTime(yearCur, monthCur, dayCur,hourCur,minutesCur,secondsCur) ;
int dt = 0 ;
CalcEcart_YearMonthDayTimeInSec( year, month, day, hour, minutes, seconds,
yearCur, monthCur, dayCur, hourCur, minutesCur, secondsCur, dt) ;
int dtMax = 0 ;
CalcTimeInSec(_hoursMax, _minutesMax, _secondsMax, dtMax) ;
if (dt < dtMax)
return true ;
return false ;
}
inline
void CMemoTime::CalcTimeInSec(int _hours, int _mn, int _s, int & _timeRes)
{
_timeRes = _hours *3600 + _mn * 60 + _s ;
}
inline
void CMemoTime::CalcEcart_TimeInSec(int _hoursA, int _mnA, int _sA,
int _hoursB, int _mnB, int _sB,int & _timeRes)
{
int tA, tB ;
tA = tB = 0 ;
CalcTimeInSec(_hoursA, _mnA, _sA, tA) ;
CalcTimeInSec(_hoursB, _mnB, _sB, tB) ;
_timeRes = abs(tB - tA) ;
}
inline
void CMemoTime::CalcEcart_DayTimeInSec(int _dayA, int _hoursA, int _mnA, int _sA,
int _dayB, int _hoursB, int _mnB, int _sB,
int & _timeRes)
{
if (_dayA == _dayB)
{
CalcEcart_TimeInSec(_hoursA, _mnA, _sA,
_hoursB, _mnB, _sB, _timeRes) ;
return ;
}
int dtA, dtB ;
dtA = dtB = 0 ;
CalcEcart_TimeInSec(_hoursA, _mnA, _sA,
24, 0, 0, dtA) ;
CalcTimeInSec(_hoursB, _mnB, _sB, dtB) ;
int dJ = 0 ;
dJ = abs((_dayB - _dayA) - 1 );
dJ *= 24 ;
dJ *= 3600 ;
_timeRes = dJ + dtA + dtB ;
}
inline
bool CMemoTime::isYearBis(int _year)
{
int yearCur = 2000 ;
while (yearCur < _year)
{
yearCur += 4 ;
}
if (yearCur == _year)
return true ;
return false ;
}
inline
void CMemoTime::CalcNbDayInMonth(int _year, int _month, int & _day)
{
switch( _month)
{
case 2 :
{
if (!isYearBis(_year))
_day = 28 ;
else _day = 29 ;
break ;
}
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 :
{
_day = 31 ;
break ;
}
case 4 :
case 6 :
case 9 :
case 11 :
{
_day = 30 ;
break ;
}
default :
{
_day = 0 ;
break ;
}
}
}
inline
void CMemoTime::CalcEcart_MonthDayTimeInSec(int _yearA, int _monthA, int _dayA, int _hoursA, int _mnA, int _sA,
int _monthB, int _dayB, int _hoursB, int _mnB, int _sB,
int & _timeRes)
{
if (_monthA == _monthB)
{
CalcEcart_DayTimeInSec(_dayA, _hoursA, _mnA, _sA,
_dayB, _hoursB, _mnB, _sB, _timeRes) ;
return ;
}
int nbDayMonthA ;
CalcNbDayInMonth(_yearA, _monthA, nbDayMonthA) ;
int dtA, dtB ;
dtA = dtB = 0 ;
CalcEcart_DayTimeInSec(_dayA,_hoursA,_mnA,_sA,nbDayMonthA,24,0,0,dtA) ;
CalcEcart_DayTimeInSec(1,0,0,0,_dayB,_hoursB, _mnB,_sB,dtB) ;
int dJ = 0 ;
dJ = abs(_monthB - _monthA) - 1 ;
if (dJ >0)
{
dJ = 0 ;
for (int count = (_monthA +1) ; count < (_monthB) ; count ++)
{
int nbJ = 0 ;
CalcNbDayInMonth(_yearA,count,nbJ) ;
dJ += nbJ ;
}
}
else dJ = 0 ;
dJ *= 24 ;
dJ *= 3600 ;
_timeRes = dJ + dtA + dtB ;
}
inline
void CMemoTime::CalcEcart_YearMonthDayTimeInSec(int _yearA, int _monthA, int _dayA, int _hoursA, int _mnA, int _sA,
int _yearB, int _monthB, int _dayB, int _hoursB, int _mnB, int _sB,
int & _timeRes)
{
if (_yearA == _yearB)
{
CalcEcart_MonthDayTimeInSec( _yearA, _monthA, _dayA, _hoursA, _mnA, _sA,
_monthB, _dayB, _hoursB, _mnB, _sB,
_timeRes) ;
return ;
}
int dtA, dtB ;
dtA = dtB = 0 ;
CalcEcart_MonthDayTimeInSec(_yearA, _monthA, _dayA, _hoursA, _mnA, _sA,
12, 31, 24,0,0, dtA) ;
CalcEcart_MonthDayTimeInSec(_yearB, 1, 1, 0, 0,0,
_monthB, _dayB, _hoursB, _mnB, _sB, dtB) ;
int dY = 0 ;
dY = abs(_yearA - _yearB) -1 ;
if (dY >0)
{
dY = 0 ;
for (int count = (_yearA +1) ; count < _yearB ; count ++)
{
int nbj ;
if (!isYearBis(count))
nbj = 365 ;
else nbj = 366 ;
dY += nbj ;
}
}
dY *= 24 ;
dY *= 3600 ;
_timeRes = dtA + dtB + dY ;
} |