summaryrefslogtreecommitdiffstats
path: root/generic/tclGetDate.y
diff options
context:
space:
mode:
authorericm <ericm>2000-01-12 01:16:08 (GMT)
committerericm <ericm>2000-01-12 01:16:08 (GMT)
commit927d806effce482081ceac9a4c2c1a1adfdb4653 (patch)
treeaad2972d4f490a96a52d231bd53b207d166c2980 /generic/tclGetDate.y
parent80aca675e000cc95aa5910d75144bada69786139 (diff)
downloadtcl-927d806effce482081ceac9a4c2c1a1adfdb4653.zip
tcl-927d806effce482081ceac9a4c2c1a1adfdb4653.tar.gz
tcl-927d806effce482081ceac9a4c2c1a1adfdb4653.tar.bz2
* generic/tclGetDate.y: Added comments for the Convert function.
* generic/tclDate.c: Fixed compiler warning issues.
Diffstat (limited to 'generic/tclGetDate.y')
-rw-r--r--generic/tclGetDate.y35
1 files changed, 33 insertions, 2 deletions
diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y
index 3625041..0f1d515 100644
--- a/generic/tclGetDate.y
+++ b/generic/tclGetDate.y
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclGetDate.y,v 1.8 2000/01/11 02:59:48 ericm Exp $
+ * RCS: @(#) $Id: tclGetDate.y,v 1.9 2000/01/12 01:16:08 ericm Exp $
*/
%{
@@ -603,7 +603,22 @@ ToSeconds(Hours, Minutes, Seconds, Meridian)
return -1; /* Should never be reached */
}
-
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Convert --
+ *
+ * Convert a {month, day, year, hours, minutes, seconds, meridian, dst}
+ * tuple into a clock seconds value.
+ *
+ * Results:
+ * 0 or -1 indicating success or failure.
+ *
+ * Side effects:
+ * Fills TimePtr with the computed value.
+ *
+ *-----------------------------------------------------------------------------
+ */
static int
Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode, TimePtr)
time_t Month;
@@ -623,13 +638,23 @@ Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode, TimePtr)
time_t Julian;
int i;
+ /* Figure out how many days are in February for the given year.
+ * Every year divisible by 4 is a leap year.
+ * But, every year divisible by 100 is not a leap year.
+ * But, every year divisible by 400 is a leap year after all.
+ */
DaysInMonth[1] = (Year % 4 == 0) && (Year % 100 != 0 || Year % 400 == 0)
? 29 : 28;
+
+ /* Check the inputs for validity */
if (Month < 1 || Month > 12
|| Year < START_OF_TIME || Year > END_OF_TIME
|| Day < 1 || Day > DaysInMonth[(int)--Month])
return -1;
+ /* Start computing the value. First determine the number of days
+ * represented by the date, then multiply by the number of seconds/day.
+ */
for (Julian = Day - 1, i = 0; i < Month; i++)
Julian += DaysInMonth[i];
if (Year >= EPOCH) {
@@ -642,10 +667,16 @@ Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode, TimePtr)
(((i % 100) != 0) || ((i % 400) == 0)));
}
Julian *= SECSPERDAY;
+
+ /* Add the timezone offset ?? */
Julian += yyTimezone * 60L;
+
+ /* Add the number of seconds represented by the time component */
if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
return -1;
Julian += tod;
+
+ /* Perform a preliminary DST compensation ?? */
if (DSTmode == DSTon
|| (DSTmode == DSTmaybe && TclpGetDate((TclpTime_t)&Julian, 0)->tm_isdst))
Julian -= 60 * 60;