Changeset 549 for XIOS/trunk/src/calendar_util.cpp
- Timestamp:
- 01/26/15 14:39:26 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/calendar_util.cpp
r545 r549 5 5 /// ////////////////////// Définitions ////////////////////// /// 6 6 7 CDuration operator*(const double & scal, const CDuration& ddr)7 CDuration operator*(const double& scal, const CDuration& ddr) 8 8 { return (ddr * scal); } 9 9 10 CDuration operator-(const CDuration & ddr , const CDuration& dr)11 { 12 CDuration dur(ddr); 13 dur.year -= dr.year; dur.month -= dr.month 10 CDuration operator-(const CDuration& ddr , const CDuration& dr) 11 { 12 CDuration dur(ddr); 13 dur.year -= dr.year; dur.month -= dr.month; dur.day -= dr.day; 14 14 dur.hour -= dr.hour; dur.minute -= dr.minute; dur.second -= dr.second; dur.timestep -= dr.timestep; 15 15 return (dur); 16 16 } 17 17 18 CDuration operator+(const CDuration & ddr , const CDuration& dr)19 { 20 CDuration dur(ddr); 21 dur.year += dr.year; dur.month += dr.month 18 CDuration operator+(const CDuration& ddr , const CDuration& dr) 19 { 20 CDuration dur(ddr); 21 dur.year += dr.year; dur.month += dr.month; dur.day += dr.day; 22 22 dur.hour += dr.hour; dur.minute += dr.minute; dur.second += dr.second; dur.timestep += dr.timestep; 23 23 return (dur); 24 24 } 25 25 26 CDuration operator*(const CDuration & ddr , const double& scal)26 CDuration operator*(const CDuration& ddr , const double& scal) 27 27 { 28 28 CDuration dur(ddr); … … 32 32 } 33 33 34 CDuration operator-(const CDuration 34 CDuration operator-(const CDuration& ddr) 35 35 { 36 36 CDuration dur(ddr); … … 47 47 //----------------------------------------------------------------- 48 48 49 CDate operator+(const CDate & dt, const CDuration& dr)50 { 51 CDuration drr 49 CDate operator+(const CDate& dt, const CDuration& dr) 50 { 51 CDuration drr(dr); 52 52 int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0; 53 const CCalendar & c = dt.getRelCalendar(); 54 55 drr.timestep=0 ; 56 drr=drr+dr.timestep*dt.getRelCalendar().getTimeStep() ; 57 58 drr.resolve(dt.getRelCalendar()); 53 const CCalendar& c = dt.getRelCalendar(); 54 55 drr.timestep = 0; 56 if (dr.timestep) 57 { 58 if (c.getTimeStep() == NoneDu) 59 ERROR("operator+(const CDate& dt, const CDuration& dr)", 60 << "Impossible to use the timestep before it is set."); 61 drr = drr + dr.timestep * c.getTimeStep(); 62 } 63 64 drr.resolve(c); 59 65 60 66 // Ajustement des minutes par rapport aux secondes. 61 67 second += dt.getSecond() + drr.second; 62 if (second < 0) { minute--; second += c.getMinuteLength(); }63 if (second >= c.getMinuteLength()) { minute 68 if (second < 0) { minute--; second += c.getMinuteLength(); } 69 if (second >= c.getMinuteLength()) { minute++; second -= c.getMinuteLength(); } 64 70 65 71 // Ajustement des heures en fonction des minutes. 66 72 minute += dt.getMinute() + drr.minute; 67 if (minute < 0) { hour 68 if (minute >= c.getHourLength()) { hour 73 if (minute < 0) { hour--; minute += c.getHourLength(); } 74 if (minute >= c.getHourLength()) { hour++; minute -= c.getHourLength(); } 69 75 70 76 // Ajustement des jours en fonction des heures. 71 77 hour += dt.getHour() + drr.hour; 72 if (hour < 0) { drr.day--; hour += c.getDayLength(); }73 if (hour >= c.getDayLength()) { drr.day 78 if (hour < 0) { drr.day--; hour += c.getDayLength(); } 79 if (hour >= c.getDayLength()) { drr.day++; hour -= c.getDayLength(); } 74 80 75 81 // Ajustement des mois en fonction des jours. 76 CDate dtt(dt); 77 drr.day +=dtt.getDay()-1;78 dtt.setDay(1) ;79 80 if ( drr.day >= 0)81 { 82 for(; c.getMonthLength(dtt) <= drr.day; dtt.addMonth 83 { drr.day -= c.getMonthLength(dtt); drr.month += 1; }84 85 day = drr.day +1;86 } 87 else 88 { 89 dtt.addMonth(-1) 90 drr.month -=1;91 for(; c.getMonthLength(dtt) < -drr.day; dtt.addMonth 92 { drr.day +=c.getMonthLength(dtt) ; drr.month-=1; }93 day =c.getMonthLength(dtt)+drr.day+1;94 } 95 82 CDate dtt(dt); 83 drr.day += dtt.getDay() - 1; 84 dtt.setDay(1); 85 86 if (drr.day >= 0) 87 { 88 for(; c.getMonthLength(dtt) <= drr.day; dtt.addMonth(1)) 89 { drr.day -= c.getMonthLength(dtt); drr.month += 1; } 90 91 day = drr.day + 1; 92 } 93 else 94 { 95 dtt.addMonth(-1); 96 drr.month -= 1; 97 for(; c.getMonthLength(dtt) < -drr.day; dtt.addMonth(-1)) 98 { drr.day += c.getMonthLength(dtt); drr.month -= 1; } 99 day = c.getMonthLength(dtt) + drr.day + 1; 100 } 101 96 102 /* 97 103 if (day < 0) { drr.month --; day += c.getMonthLength(dtt); } 98 104 if (day > c.getMonthLength(dtt)) { drr.month ++; day -= c.getMonthLength(dtt); } // << ProblÚme ici 99 105 if (day == 0){ day = c.getMonthLength(dtt); drr.month --; } 100 */ 101 drr.resolve( dt.getRelCalendar());106 */ 107 drr.resolve(c); 102 108 103 109 // Ajustement des années en fonction des mois. 104 110 month += dt.getMonth() + drr.month; 105 if (month < 0) { drr.year--; month += c.getYearLength(); }106 if (month > c.getYearLength()) { drr.year++; month -= c.getYearLength(); }111 if (month < 0) { drr.year--; month += c.getYearLength(); } 112 if (month > c.getYearLength()) { drr.year++; month -= c.getYearLength(); } 107 113 if (month == 0){ month = c.getYearLength(); drr.year--; } 108 114 109 115 year += dt.getYear() + drr.year; 110 116 111 return (CDate( dt.getRelCalendar(), year, month, day, hour, minute, second));112 } 113 114 CDate operator-(const CDate & dt, const CDuration& dr) { return (dt + (-dr)); }115 116 //----------------------------------------------------------------- 117 118 CDuration operator-(const CDate & dt0, const CDate& dt1)117 return (CDate(c, year, month, day, hour, minute, second)); 118 } 119 120 CDate operator-(const CDate& dt, const CDuration& dr) { return (dt + (-dr)); } 121 122 //----------------------------------------------------------------- 123 124 CDuration operator-(const CDate& dt0, const CDate& dt1) 119 125 { 120 126 // TODO :: Vérifier que les deux dates (dt0 et dt1) ont une référence vers le même calendrier. … … 131 137 bool operator==(const CDuration& ddr, const CDuration& dr) 132 138 { 133 return ((ddr.year == dr.year) && (ddr.month == dr.month) && (dr.day == ddr.day)&&134 (ddr.hour == dr.hour) && (ddr.minute == dr.minute) && (dr.second == ddr.second)&&139 return ((ddr.year == dr.year)&& (ddr.month == dr.month) && (dr.day == ddr.day)&& 140 (ddr.hour == dr.hour)&& (ddr.minute == dr.minute)&& (dr.second == ddr.second)&& 135 141 (ddr.timestep == dr.timestep)); 136 142 } … … 144 150 { 145 151 // TODO :: Vérifier que les deux dates (dt0 et dt1) ont une référence vers le même calendrier. 146 return ((dt0.getYear() == dt1.getYear()) && (dt0.getMonth() == dt1.getMonth()) && (dt1.getDay() == dt0.getDay())&&147 (dt0.getHour() == dt1.getHour()) && (dt0.getMinute() == dt1.getMinute())&& (dt1.getSecond() == dt0.getSecond()));152 return ((dt0.getYear() == dt1.getYear())&& (dt0.getMonth() == dt1.getMonth()) && (dt1.getDay() == dt0.getDay())&& 153 (dt0.getHour() == dt1.getHour())&& (dt0.getMinute() == dt1.getMinute())&& (dt1.getSecond() == dt0.getSecond())); 148 154 } 149 155 … … 152 158 // TODO :: Vérifier que les deux dates (dt0 et dt1) ont une référence vers le même calendrier. 153 159 if (dt0.getYear() < dt1.getYear()) 154 { 160 { 155 161 return true; 156 162 } 157 163 else if (dt0.getYear() == dt1.getYear()) 158 { 164 { 159 165 if (dt0.getMonth() < dt1.getMonth()) 160 166 { … … 174 180 } 175 181 else if (dt0.getHour() == dt1.getHour()) 176 { 182 { 177 183 if (dt0.getMinute() < dt1.getMinute()) 178 184 { … … 193 199 //----------------------------------------------------------------- 194 200 195 bool operator!=(const CDate & dt0, const CDate& dt1){ return !(dt1 == dt0); }196 bool operator> (const CDate & dt0, const CDate& dt1){ return (dt1 < dt0); }197 bool operator>=(const CDate & dt0, const CDate& dt1){ return ((dt0 > dt1) || (dt1 == dt0)); }198 bool operator<=(const CDate & dt0, const CDate& dt1){ return ((dt0 < dt1) || (dt1 == dt0)); }201 bool operator!=(const CDate& dt0, const CDate& dt1){ return !(dt1 == dt0); } 202 bool operator> (const CDate& dt0, const CDate& dt1){ return (dt1 < dt0); } 203 bool operator>=(const CDate& dt0, const CDate& dt1){ return ((dt0 > dt1) || (dt1 == dt0)); } 204 bool operator<=(const CDate& dt0, const CDate& dt1){ return ((dt0 < dt1) || (dt1 == dt0)); } 199 205 200 206 ///----------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.