IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 21, 2004, 3:03:18 PM (22 years ago)
Author:
harman
Message:

Added more functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psTime.c

    r1248 r1256  
    66 *  A collection of functions are required by psLib to manipulate time data. These functions primarily consist
    77 *  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 within
    9  *  psLib, except those noted, are calculated in terms of TAI time, which is approxinmately 32 seconds faster
    10  *  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.
    1111 *
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-07-21 01:56:28 $
     14 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-07-22 01:02:53 $
    1616 *
    1717 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    153153
    154154    // 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];
    156156
    157157    return time;
     
    280280    }
    281281
    282     month = atoi(strtok(tempString, "/"));
     282    month = atoi(strtok(NULL, "/"));
    283283    if(month<1 || month>12) {
    284284        psError(__func__,"Month must have a value from 0 to 11. Value: %d", month);
    285285    }
    286286
    287     day = atoi(strtok(tempString, ","));
     287    day = atoi(strtok(NULL, ","));
    288288    if(day<1 || day>31) {
    289289        psError(__func__,"Day must have a value from 1 to 31. Value: %d", day);
    290290    }
    291291
    292     hour = atoi(strtok(tempString, ":"));
     292    hour = atoi(strtok(NULL, ":"));
    293293    if(hour<0 || hour>23) {
    294294        psError(__func__,"Hour must have a value from 0 to 23. Value: %d", hour);
    295295    }
    296296
    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) {
    299304        psError(__func__,"Second must have a value from 0 to 59. Value: %d", second);
    300305    }
    301306
    302     millisecond = atoi(strtok(tempString, "X"));
     307    millisecond = atoi(strtok(NULL, "X"));
    303308    if(millisecond<0 || millisecond>1000) {
    304309        psError(__func__,"Second must have a value from 0 to 999. Value: %d", millisecond);
     
    311316    tmTime.tm_min = minute;
    312317    tmTime.tm_sec = second;
     318    tmTime.tm_isdst = -1;
    313319
    314320    // Convert tm time to psTime
     
    326332
    327333    // 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];
    330335    outTime.tv_usec = time.tv_usec;
    331336    CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime);
    332337
    333     return time;
     338    return outTime;
    334339}
    335340
     
    406411{
    407412    int i;
    408     int m;
    409413    int n;
    410414    int y;
     
    414418
    415419    i= 0;
    416     m = 0;
    417420    n = 0;
    418421    y = 0;
     
    429432    }
    430433
     434    // Back to 1969
    431435    n = time->tm_year + 1900 - 1;
    432436    epoch = (time->tm_year - 70) * SEC_PER_YEAR + ((n/4 - n/100 + n/400) -
     
    435439    y = time->tm_year + 1900;
    436440
    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)) {
    441446            epoch += SEC_PER_DAY;
    442447        }
    443 
    444         if(++m > 11) {
    445             m = 0;
    446             y++;
    447         }
    448     }
    449 
     448    }
     449
     450    // Add everything
    450451    epoch += (time->tm_mday - 1) * SEC_PER_DAY;
    451452    epoch += time->tm_hour *SEC_PER_HOUR + time->tm_min * SEC_PER_MINUTE + time->tm_sec;
    452453
     454    // Create psTime
    453455    outTime.tv_usec = 0;
    454456    outTime.tv_sec = epoch;
    455457
    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.