Changeset 98 for trunk/orca
- Timestamp:
- 03/23/06 01:35:12 (3 years ago)
- Location:
- trunk/orca
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/orca/op.c
r65 r98 144 144 if( orIs(b, OT_TIME) ) 145 145 { 146 OTime time; 147 OValue* res; 148 149 time.sec = a->time.sec + b->time.sec; 150 time.usec = a->time.usec + b->time.usec; 151 if( time.usec > 1000000 ) 152 { 153 time.sec += 1; 154 time.usec -= 1000000; 155 } 156 157 res = orRESULT; 158 orSetTF( res, OT_TIME ); 159 res->time = time; 146 orSeconds(a) += orSeconds(b); 160 147 return; 161 148 } … … 283 270 if( orIs(b, OT_TIME) ) 284 271 { 285 OTime btime; 286 OValue* res; 287 288 // http://www.dusek.ch/manual/glibc/libc_21.html 289 290 btime = b->time; 291 if( a->time.usec < btime.usec ) 292 { 293 int nsec = (btime.usec - a->time.usec) / 1000000 + 1; 294 btime.usec -= 1000000 * nsec; 295 btime.sec += nsec; 296 } 297 if( a->time.usec - btime.usec > 1000000 ) 298 { 299 int nsec = (a->time.usec - btime.usec) / 1000000; 300 btime.usec += 1000000 * nsec; 301 btime.sec -= nsec; 302 } 303 304 res = orRESULT; 305 orSetTF( res, OT_TIME ); 306 /* usec will always be positive. */ 307 res->time.sec = a->time.sec - btime.sec; 308 res->time.usec = a->time.usec - btime.usec; 309 /* 310 if( a->time.sec < time.sec ) 311 res->time.sec = - res->time.sec; 312 */ 272 orSeconds(a) -= orSeconds(b); 313 273 return; 314 274 } -
trunk/orca/ovalue.h
r86 r98 169 169 170 170 171 typedef struct172 {173 int32_t sec;174 int32_t usec;175 }176 OTime;177 178 179 171 typedef void (*ONativeFunc)(void*); 180 172 … … 204 196 OWordRef word; 205 197 OContext ctx; 206 OTime time;207 198 struct { 208 199 OIndex n; … … 494 485 #define orLogic(val) (val)->integer 495 486 #define orDecimal(val) (val)->num.decimal 487 #define orSeconds(val) (val)->num.decimal 496 488 #define orTupleLen(val) (val)->argc 497 489 -
trunk/orca/print.c
r96 r98 202 202 int yc; 203 203 204 tt = val->time.sec;204 tt = (time_t) orSeconds(val); 205 205 st = localtime( &tt ); 206 206 … … 241 241 242 242 243 static void moldTime( OString* out, const OValue* val ) 244 { 245 char* cp; 246 247 orArrayReserve( out, 1, out->used + 32 ); 248 249 cp = out->charArray + out->used; 250 strPrint( cp, "%f", orSeconds(val) ); 251 while( *cp != '\0' ) 252 ++cp; 253 out->used = cp - out->charArray; 254 } 255 256 243 257 static void formList( OString* out, const OValue* val ) 244 258 { … … 578 592 break; 579 593 580 case OT_TIME: { 581 double d; 582 char* cp; 583 d = ((double) val->time.sec) + 584 ((double) val->time.usec * 0.000001); 585 orArrayReserve( out, 1, out->used + 32 ); 586 cp = out->charArray + out->used; 587 strPrint( cp, "%f", d ); 588 while( *cp != '\0' ) 589 ++cp; 590 out->used = cp - out->charArray; 591 } 594 case OT_TIME: moldTime( out, val ); 592 595 break; 593 596 … … 890 893 break; 891 894 892 case OT_TIME: { 893 double d; 894 char* cp; 895 d = ((double) val->time.sec) + 896 ((double) val->time.usec * 0.000001); 897 orArrayReserve( out, 1, out->used + 32 ); 898 cp = out->charArray + out->used; 899 strPrint( cp, "%f", d ); 900 while( *cp != '\0' ) 901 ++cp; 902 out->used = cp - out->charArray; 903 } 895 case OT_TIME: moldTime( out, val ); 904 896 break; 905 897 -
trunk/orca/unix/os.c
r71 r98 75 75 76 76 orSetTF( res, OT_TIME ); 77 res->time.sec = buf.st_mtime; 78 res->time.usec = 0; 77 orSeconds(res) = buf.st_mtime; 79 78 return 0; 80 79 } … … 156 155 orSetTF( res, OT_DATE ); 157 156 158 res->time.sec = tp.tv_sec; 159 res->time.usec = tp.tv_usec; 157 orSeconds(res) = tp.tv_sec + (tp.tv_usec * 0.000001); 160 158 } 161 159 -
trunk/orca/win32/os.c
r85 r98 173 173 else 174 174 orSetTF( res, OT_DATE ); 175 res->time.sec = tb.time; 176 res->time.usec = tb.millitm * 1000; 175 orSeconds(res) = tb.time + (tb.millitm * 0.001); 177 176 } 178 177
