Changeset 1256 for trunk/psLib/src/astronomy/psTime.c
- Timestamp:
- Jul 21, 2004, 3:03:18 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astronomy/psTime.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astronomy/psTime.c
r1248 r1256 6 6 * A collection of functions are required by psLib to manipulate time data. These functions primarily consist 7 7 * of conversions between specific time formats. PSLib currently uses the UNIX timeval time system as the 8 * base upon which International Atomic Time (TAI) time is calculated. All time conversion functions within9 * psLib, except those noted, are calculated in terms of TAI time, which is approxinmately 32 seconds faster10 * than UTC/timeval.8 * base upon which International Atomic Time (TAI) time is calculated. TAI time varies over time due to the 9 * earth's rotation and the movement of the continental plates. It is currentls 32 seconds faster than 10 * UTC/timeval time. 11 11 * 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-07-2 1 01:56:28$14 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-07-22 01:02:53 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 153 153 154 154 // Add most current leapseconds value to UTC time to get TAI time 155 time.tv_sec += leapseconds[NUM_LEAPSECOND_UPDATES ][1];155 time.tv_sec += leapseconds[NUM_LEAPSECOND_UPDATES-1][1]; 156 156 157 157 return time; … … 280 280 } 281 281 282 month = atoi(strtok( tempString, "/"));282 month = atoi(strtok(NULL, "/")); 283 283 if(month<1 || month>12) { 284 284 psError(__func__,"Month must have a value from 0 to 11. Value: %d", month); 285 285 } 286 286 287 day = atoi(strtok( tempString, ","));287 day = atoi(strtok(NULL, ",")); 288 288 if(day<1 || day>31) { 289 289 psError(__func__,"Day must have a value from 1 to 31. Value: %d", day); 290 290 } 291 291 292 hour = atoi(strtok( tempString, ":"));292 hour = atoi(strtok(NULL, ":")); 293 293 if(hour<0 || hour>23) { 294 294 psError(__func__,"Hour must have a value from 0 to 23. Value: %d", hour); 295 295 } 296 296 297 second = atoi(strtok(tempString, ".")); 298 if(second<0 || second>60) { 297 minute = atoi(strtok(NULL, ":")); 298 if(minute<0 || minute>59) { 299 psError(__func__,"Minute must have a value from 0 to 59. Value: %d", minute); 300 } 301 302 second = atoi(strtok(NULL, ".")); 303 if(second<0 || second>59) { 299 304 psError(__func__,"Second must have a value from 0 to 59. Value: %d", second); 300 305 } 301 306 302 millisecond = atoi(strtok( tempString, "X"));307 millisecond = atoi(strtok(NULL, "X")); 303 308 if(millisecond<0 || millisecond>1000) { 304 309 psError(__func__,"Second must have a value from 0 to 999. Value: %d", millisecond); … … 311 316 tmTime.tm_min = minute; 312 317 tmTime.tm_sec = second; 318 tmTime.tm_isdst = -1; 313 319 314 320 // Convert tm time to psTime … … 326 332 327 333 // Convert UTC time to psTime/TAI 328 outTime.tv_sec = time.tv_sec + leapseconds[NUM_LEAPSECOND_UPDATES][1]; 329 ; 334 outTime.tv_sec = time.tv_sec + leapseconds[NUM_LEAPSECOND_UPDATES-1][1]; 330 335 outTime.tv_usec = time.tv_usec; 331 336 CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime); 332 337 333 return time;338 return outTime; 334 339 } 335 340 … … 406 411 { 407 412 int i; 408 int m;409 413 int n; 410 414 int y; … … 414 418 415 419 i= 0; 416 m = 0;417 420 n = 0; 418 421 y = 0; … … 429 432 } 430 433 434 // Back to 1969 431 435 n = time->tm_year + 1900 - 1; 432 436 epoch = (time->tm_year - 70) * SEC_PER_YEAR + ((n/4 - n/100 + n/400) - … … 435 439 y = time->tm_year + 1900; 436 440 437 for(i = 0; i < time->tm_mon; i++) 438 { 439 epoch += mon [m] * SEC_PER_DAY; 440 if(m == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) { 441 // Adjust for leap years 442 for(i = 0; i<time->tm_mon; i++) 443 { 444 epoch += mon [i] * SEC_PER_DAY; 445 if(i == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) { 441 446 epoch += SEC_PER_DAY; 442 447 } 443 444 if(++m > 11) { 445 m = 0; 446 y++; 447 } 448 } 449 448 } 449 450 // Add everything 450 451 epoch += (time->tm_mday - 1) * SEC_PER_DAY; 451 452 epoch += time->tm_hour *SEC_PER_HOUR + time->tm_min * SEC_PER_MINUTE + time->tm_sec; 452 453 454 // Create psTime 453 455 outTime.tv_usec = 0; 454 456 outTime.tv_sec = epoch; 455 457 456 return outTime; 457 } 458 CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime); 459 460 return outTime; 461 }
Note:
See TracChangeset
for help on using the changeset viewer.
