Changeset 2826 in Sophya for trunk/SophyaLib/BaseTools/timestamp.cc
- Timestamp:
- Nov 2, 2005, 9:52:39 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/timestamp.cc
r2805 r2826 69 69 } 70 70 71 TimeStamp::TimeStamp(int_8 days, r_8 seconds) 72 { 73 Set(days, seconds); 74 } 75 71 76 TimeStamp::TimeStamp(string& date, string& hour) 72 77 { … … 90 95 void TimeStamp::Set(double days) 91 96 { 92 if (days <0.) {93 mDays = days;94 mSeconds = (days- mDays)*86400.;97 if (days >= 0.) { 98 mDays = trunc(days); 99 mSeconds = (days-trunc(days))*86400.; 95 100 } 96 101 else { 97 mDays = trunc(days)-1; 98 mSeconds = (days-mDays)*86400.; 99 } 102 if ( (trunc(days)-days) > 0.) { 103 mDays = trunc(days)-1; 104 mSeconds = (days-mDays)*86400.; 105 } 106 else { 107 mDays = trunc(days); 108 mSeconds = 0.; 109 } 110 } 111 } 112 113 void TimeStamp::Set(int_8 days, r_8 seconds) 114 { 115 if ( (seconds < 0.) || (seconds > 86400.) ) 116 throw ParmError("TimeStamp::Set(int_8, r_8) seconds<0 or seconds>86400."); 117 mDays = days; 100 118 } 101 119 … … 178 196 seconds -= hour*3600; 179 197 min = trunc(seconds/60.); 198 while (min >= 60) { hour++; min -= 60; } 180 199 sec = seconds-min*60; 181 } 200 while (sec >= 60.) { min++; sec -= 60.; } 201 } 202 182 203 double TimeStamp::ToDays() const 183 204 { … … 185 206 } 186 207 187 string TimeStamp::ToString() const 208 /*! 209 \param fgday : if false, ignore the date (dd/mm/yy) part 210 \param fghour : if false, ignore the hour (hh:mm:ss) part 211 */ 212 string TimeStamp::ToString(bool fgday, bool fghour) const 188 213 { 189 214 char buff[128]; … … 193 218 GetDate(aa, mm, jj); 194 219 GetHour(hh, min, sec); 195 sprintf(buff,"%02d/%02d/%02d %02d:%02d:%02.1f GMT", jj,mm,aa,hh,min,sec); 220 if (!fghour) 221 sprintf(buff,"%02d/%02d/%02d ", jj,mm,aa); 222 else if (!fgday) 223 sprintf(buff,"%02d:%02d:%02.3f ", hh,min,sec); 224 else 225 sprintf(buff,"%02d/%02d/%02d %02d:%02d:%02.1f GMT", jj,mm,aa,hh,min,sec); 196 226 return buff; 197 227 } 198 228 199 void TimeStamp::Print(ostream& os) const 200 { 201 os << " " << ToString() << " "; 229 /*! 230 \param fgday : if false, ignore the date (dd/mm/yy) part 231 \param fghour : if false, ignore the hour (hh:mm:ss) part 232 */ 233 void TimeStamp::Print(ostream& os, bool fgday, bool fghour) const 234 { 235 os << " " << ToString(fgday, fghour) << " "; 202 236 } 203 237
Note:
See TracChangeset
for help on using the changeset viewer.