Index: trunk/psLib/src/astronomy/psTime.c
===================================================================
--- trunk/psLib/src/astronomy/psTime.c	(revision 1248)
+++ trunk/psLib/src/astronomy/psTime.c	(revision 1256)
@@ -6,12 +6,12 @@
  *  A collection of functions are required by psLib to manipulate time data. These functions primarily consist
  *  of conversions between specific time formats.  PSLib currently uses the UNIX timeval time system as the
- *  base upon which International Atomic Time (TAI) time is calculated. All time conversion functions within
- *  psLib, except those noted, are calculated in terms of TAI time, which is approxinmately 32 seconds faster
- *  than UTC/timeval.
+ *  base upon which International Atomic Time (TAI) time is calculated. TAI time varies over time due to the
+ *  earth's rotation and the movement of the continental plates. It is currentls 32 seconds faster than
+ *  UTC/timeval time.
  *
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-21 01:56:28 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-22 01:02:53 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -153,5 +153,5 @@
 
     // Add most current leapseconds value to UTC time to get TAI time
-    time.tv_sec += leapseconds[NUM_LEAPSECOND_UPDATES][1];
+    time.tv_sec += leapseconds[NUM_LEAPSECOND_UPDATES-1][1];
 
     return time;
@@ -280,25 +280,30 @@
     }
 
-    month = atoi(strtok(tempString, "/"));
+    month = atoi(strtok(NULL, "/"));
     if(month<1 || month>12) {
         psError(__func__,"Month must have a value from 0 to 11. Value: %d", month);
     }
 
-    day = atoi(strtok(tempString, ","));
+    day = atoi(strtok(NULL, ","));
     if(day<1 || day>31) {
         psError(__func__,"Day must have a value from 1 to 31. Value: %d", day);
     }
 
-    hour = atoi(strtok(tempString, ":"));
+    hour = atoi(strtok(NULL, ":"));
     if(hour<0 || hour>23) {
         psError(__func__,"Hour must have a value from 0 to 23. Value: %d", hour);
     }
 
-    second = atoi(strtok(tempString, "."));
-    if(second<0 || second>60) {
+    minute = atoi(strtok(NULL, ":"));
+    if(minute<0 || minute>59) {
+        psError(__func__,"Minute must have a value from 0 to 59. Value: %d", minute);
+    }
+
+    second = atoi(strtok(NULL, "."));
+    if(second<0 || second>59) {
         psError(__func__,"Second must have a value from 0 to 59. Value: %d", second);
     }
 
-    millisecond = atoi(strtok(tempString, "X"));
+    millisecond = atoi(strtok(NULL, "X"));
     if(millisecond<0 || millisecond>1000) {
         psError(__func__,"Second must have a value from 0 to 999. Value: %d", millisecond);
@@ -311,4 +316,5 @@
     tmTime.tm_min = minute;
     tmTime.tm_sec = second;
+    tmTime.tm_isdst = -1;
 
     // Convert tm time to psTime
@@ -326,10 +332,9 @@
 
     // Convert UTC time to psTime/TAI
-    outTime.tv_sec = time.tv_sec + leapseconds[NUM_LEAPSECOND_UPDATES][1];
-    ;
+    outTime.tv_sec = time.tv_sec + leapseconds[NUM_LEAPSECOND_UPDATES-1][1];
     outTime.tv_usec = time.tv_usec;
     CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime);
 
-    return time;
+    return outTime;
 }
 
@@ -406,5 +411,4 @@
 {
     int i;
-    int m;
     int n;
     int y;
@@ -414,5 +418,4 @@
 
     i= 0;
-    m = 0;
     n = 0;
     y = 0;
@@ -429,4 +432,5 @@
     }
 
+    // Back to 1969
     n = time->tm_year + 1900 - 1;
     epoch = (time->tm_year - 70) * SEC_PER_YEAR + ((n/4 - n/100 + n/400) -
@@ -435,23 +439,23 @@
     y = time->tm_year + 1900;
 
-    for(i = 0; i < time->tm_mon; i++)
-    {
-        epoch += mon [m] * SEC_PER_DAY;
-        if(m == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {
+    // Adjust for leap years
+    for(i = 0; i<time->tm_mon; i++)
+    {
+        epoch += mon [i] * SEC_PER_DAY;
+        if(i == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {
             epoch += SEC_PER_DAY;
         }
-
-        if(++m > 11) {
-            m = 0;
-            y++;
-        }
-    }
-
+    }
+
+    // Add everything
     epoch += (time->tm_mday - 1) * SEC_PER_DAY;
     epoch += time->tm_hour *SEC_PER_HOUR + time->tm_min * SEC_PER_MINUTE + time->tm_sec;
 
+    // Create psTime
     outTime.tv_usec = 0;
     outTime.tv_sec = epoch;
 
-    return outTime;
-}
+    CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime);
+
+    return outTime;
+}
