diff options
author | stanton <stanton> | 1999-03-04 00:58:26 (GMT) |
---|---|---|
committer | stanton <stanton> | 1999-03-04 00:58:26 (GMT) |
commit | 27b44243dd6de0bf7f1aa0bb831d41b7b41f4a2a (patch) | |
tree | 822d6380276c0a2ae924446f816403d0176a89af | |
parent | 0f95a59075710ed4b5a19a6be5fc8b879cae8103 (diff) | |
download | tcl-27b44243dd6de0bf7f1aa0bb831d41b7b41f4a2a.zip tcl-27b44243dd6de0bf7f1aa0bb831d41b7b41f4a2a.tar.gz tcl-27b44243dd6de0bf7f1aa0bb831d41b7b41f4a2a.tar.bz2 |
* unix/tclUnixTime.c: Added TclpGetDate and TclStrftime.
* win/tclWinTime.c:
* unix/tclUnixTime.c:
* mac/tclMacTime.c:
* generic/tclDate.c:
* generic/tclClock.c: Created a new opaque TclpTime_t type so
generic functions that depend on the format of time_t can appear
in the generic header files.
-rw-r--r-- | generic/tclClock.c | 4 | ||||
-rw-r--r-- | generic/tclDate.c | 14 | ||||
-rw-r--r-- | mac/tclMacTime.c | 5 | ||||
-rw-r--r-- | unix/tclUnixTime.c | 60 | ||||
-rw-r--r-- | win/tclWinTime.c | 8 |
5 files changed, 76 insertions, 15 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c index d550aaa..fbbffde 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -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: tclClock.c,v 1.2 1998/09/14 18:39:57 stanton Exp $ + * RCS: @(#) $Id: tclClock.c,v 1.2.4.1 1999/03/04 00:58:26 stanton Exp $ */ #include "tcl.h" @@ -263,7 +263,7 @@ FormatClock(interp, clockVal, useGMT, format) } #endif - timeDataPtr = TclpGetDate((time_t *) &clockVal, useGMT); + timeDataPtr = TclpGetDate((TclpTime_t) &clockVal, useGMT); /* * Make a guess at the upper limit on the substituted string size diff --git a/generic/tclDate.c b/generic/tclDate.c index 7afe99c..a4f45a8 100644 --- a/generic/tclDate.c +++ b/generic/tclDate.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclDate.c,v 1.2 1998/09/14 18:39:58 stanton Exp $ + * RCS: @(#) $Id: tclDate.c,v 1.2.4.1 1999/03/04 00:58:26 stanton Exp $ */ #include "tclInt.h" @@ -441,7 +441,7 @@ Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode, TimePtr) return -1; Julian += tod; if (DSTmode == DSTon - || (DSTmode == DSTmaybe && TclpGetDate(&Julian, 0)->tm_isdst)) + || (DSTmode == DSTmaybe && TclpGetDate((TclpTime_t)&Julian, 0)->tm_isdst)) Julian -= 60 * 60; *TimePtr = Julian; return 0; @@ -456,8 +456,8 @@ DSTcorrect(Start, Future) time_t StartDay; time_t FutureDay; - StartDay = (TclpGetDate(&Start, 0)->tm_hour + 1) % 24; - FutureDay = (TclpGetDate(&Future, 0)->tm_hour + 1) % 24; + StartDay = (TclpGetDate((TclpTime_t)&Start, 0)->tm_hour + 1) % 24; + FutureDay = (TclpGetDate((TclpTime_t)&Future, 0)->tm_hour + 1) % 24; return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; } @@ -472,7 +472,7 @@ RelativeDate(Start, DayOrdinal, DayNumber) time_t now; now = Start; - tm = TclpGetDate(&now, 0); + tm = TclpGetDate((TclpTime_t)&now, 0); now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); return DSTcorrect(Start, now); @@ -495,7 +495,7 @@ RelativeMonth(Start, RelMonth, TimePtr) *TimePtr = 0; return 0; } - tm = TclpGetDate(&Start, 0); + tm = TclpGetDate((TclpTime_t)&Start, 0); Month = 12 * (tm->tm_year + TM_YEAR_BASE) + tm->tm_mon + RelMonth; Year = Month / 12; Month = Month % 12 + 1; @@ -726,7 +726,7 @@ TclGetDate(p, now, zone, timePtr) int thisyear; TclDateInput = p; - tm = TclpGetDate((time_t *) &now, 0); + tm = TclpGetDate((TclpTime_t) &now, 0); thisyear = tm->tm_year + TM_YEAR_BASE; TclDateYear = thisyear; TclDateMonth = tm->tm_mon + 1; diff --git a/mac/tclMacTime.c b/mac/tclMacTime.c index 79633de..bcb52d1 100644 --- a/mac/tclMacTime.c +++ b/mac/tclMacTime.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclMacTime.c,v 1.2 1998/09/14 18:40:07 stanton Exp $ + * RCS: @(#) $Id: tclMacTime.c,v 1.2.4.1 1999/03/04 00:58:26 stanton Exp $ */ #include "tclInt.h" @@ -241,9 +241,10 @@ TclpGetTime( struct tm * TclpGetDate( - const time_t *tp, /* Time struct to fill. */ + TclpTime_t time, /* Time struct to fill. */ int useGMT) /* True if date should reflect GNT time. */ { + const time_t *tp = (const time_t *)time; DateTimeRec dtr; MachineLocation loc; long int offset; diff --git a/unix/tclUnixTime.c b/unix/tclUnixTime.c index b330d84..e2981ce 100644 --- a/unix/tclUnixTime.c +++ b/unix/tclUnixTime.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixTime.c,v 1.2 1998/09/14 18:40:18 stanton Exp $ + * RCS: @(#) $Id: tclUnixTime.c,v 1.2.4.1 1999/03/04 00:58:27 stanton Exp $ */ #include "tclInt.h" @@ -234,3 +234,61 @@ TclpGetTime(timePtr) timePtr->sec = tv.tv_sec; timePtr->usec = tv.tv_usec; } + +/* + *---------------------------------------------------------------------- + * + * TclpGetDate -- + * + * This function converts between seconds and struct tm. If + * useGMT is true, then the returned date will be in Greenwich + * Mean Time (GMT). Otherwise, it will be in the local time zone. + * + * Results: + * Returns a static tm structure. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +struct tm * +TclpGetDate(time, useGMT) + TclpTime_t time; + int useGMT; +{ + const time_t *tp = (const time_t *)time; + + if (useGMT) { + return gmtime(tp); + } else { + return localtime(tp); + } +} + +/* + *---------------------------------------------------------------------- + * + * TclStrftime -- + * + * On Unix, we can safely call the native strftime implementation. + * + * Results: + * The normal strftime result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +size_t +TclStrftime(s, maxsize, format, t) + char *s; + size_t maxsize; + const char *format; + const struct tm *t; +{ + return strftime(s, maxsize, format, t); +} diff --git a/win/tclWinTime.c b/win/tclWinTime.c index 089a057..48b6e1a 100644 --- a/win/tclWinTime.c +++ b/win/tclWinTime.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinTime.c,v 1.2 1998/09/14 18:40:20 stanton Exp $ + * RCS: @(#) $Id: tclWinTime.c,v 1.2.4.1 1999/03/04 00:58:27 stanton Exp $ */ #include "tclInt.h" @@ -191,10 +191,12 @@ TclpGetTZName() */ struct tm * -TclpGetDate(tp, useGMT) - const time_t *tp; +TclpGetDate(t, useGMT) + TclpTime_t t; int useGMT; { + const time_t *tp = (const time_t *) t; + struct tm *tmPtr; long time; |