CTime
DLL from CanalRun |
Introduction Ctime is a Win32 DLL to use with Delphi v2 & v3 that converts between Borland's TDateTime and the struct tm and time_t values used in the standard "C" library and many Windows and Dos applications. For example, the WinNT 4.0 Event Log uses two time_t variables to hold event record time and date values. Time_t denotes the number of seconds since January 1, 1970 at 00:00:00. It will hold times/dates up to the year 2038. CTime is provided AS IS with no warranties expressed or implied. CanalRun or its agents cannot be held liable for any direct or indirect damages resulting from the use of this software. If in doubt, don't use it. Register CTime is shareware. The shareware version is limited to converting values for the year 1980. This restriction still allows you to fully test the DLL. The registration cost for CTime is $5 US. Click here for the order form. Installation To install CTime, unzip the contents of the distribution file into an empty directory. The file CTime1s.dll is the shareware time_t converter DLL. An example with Delphi 3 source, CVTst.Exe, is also present. Double-click on CVTst.Exe. Using CTime with Delphi To use the CTime dll with Delphi, copy CTime1s.dll into the same directory as the Delphi executable from your project. (Alternatively you could put the dll in the Windows/System directory). Then add the following three external function definitions to the pas file from which the functions are called. See the example Main.Pas for additional help. function clocaltime(var tms: tmRecord; var tim: Integer): Integer; stdcall; external 'CTime1s.dll'; function cgmtime(var tms: tmRecord; var tim: Integer): Integer; stdcall; external 'CTime1s.dll'; function cmktime(var tms: tmRecord; var tim: Integer): Integer; stdcall; external 'CTime1s.dll'; Don't forget the "stdcall" or you will get very unpredictable results. Also insert the Record definition for the TM structure. tmRecord = record sec: Integer; // seconds after the minute - [0,59] min: Integer; // minutes after the hour - [0,59] hour: Integer; // hours since midnight - [0,23] mday: Integer; // day of the month - [1,31] mon: Integer; // months since January - [1,12] year: Integer; // years since 1900 wday: Integer; // days since Sunday - [1,7] yday: Integer; // days since January 1 - [1,366] isdst: Integer; // daylight savings time flag end; A function to encode the tm structure into a TDateTime is included in the example. function tmToDateTime(var tms: tmRecord): TDateTime; clocaltime Converts a time value and corrects for the local time zone. function clocaltime(var tms: tmRecord; var tim: Integer): Integer; stdcall; external 'CTime1s.dll'; clocaltime returns the tmRecord tms. If the value in tim represents a date before midnight, January 1, 1970, clocaltime returns 0. The fields of the record type tm store the following values, each of which is an integer: sec Seconds after minute (0 59) min Minutes after hour (0 59) hour Hours after midnight (0 23) mday Day of month (1 31) mon Month (1 12; January = 1) year Year (1980 - 2038) wday Day of week (1 6; Sunday = 1) yday Day of year (1 366; January 1 = 1) isdst Positive value if daylight saving time is in effect; 0 if daylight saving time is not in effect; negative value if status of daylight saving time is unknown. The run-time library assumes the United States's rules for implementing the calculation of Daylight Saving Time (DST). The clocaltime function converts a time stored as a tim value and stores the result in a record of type tm. The long value tim represents the seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC). This value is usually obtained from the time function. Clocaltime corrects for the local time zone if the user first sets the global environment variable TZ. When TZ is set, three other environment variables (_timezone, _daylight, and _tzname) are automatically set as well. cgmtime Converts a time value to a structure. function cgmtime(var tms: tmRecord; var tim: Integer): Integer; stdcall; external 'CTime1s.dll'; cgmtime fills the tmRecord pointed to by tms. The fields of the returned record hold the evaluated value of the tim argument in UTC rather than in local time. Each of the record fields is of type int, see above. cmktime Converts the local time to a calendar value stored in a tmRecord. function cmktime(var tms: tmRecord; var tim: Integer): Integer; stdcall; external 'CTime1s.dll'; The cmktime function converts the supplied tmRecord (possibly incomplete) in tms into a fully defined tmRecord with normalized values and then converts it to an Integer time value. The original values of the wday and yday components of the tms record are ignored, and the original values of the other components are not restricted to their normal ranges. Cmktime handles dates in any time zone from midnight, January 1, 1970, to midnight, February 5, 2036. If successful, mktime sets the values of wday and yday as appropriate and sets the other components to represent the specified calendar time, but with their values forced to the normal ranges; the final value of mday is not set until mon and year are determined. When specifying a tms time, set the isdst field to 0 to indicate that standard time is in effect, or to a value greater than 0 to indicate that daylight savings time is in effect, or to a value less than zero to have the run-time library code compute whether standard time or daylight savings time is in effect. (The run-time library assumes the United States's rules for implementing the calculation of Daylight Saving Time). isdst is a required field. If not set, its value is undefined and the return value from mktime is unpredictable. About CanalRun CanalRun, Inc. has been in the shareware business since 1992. You can visit the CanalRun web site at www.canalrun.com. The latest versions of shareware are always available there first For general comments or questions or for help with CTime, you can Email CanalRun at support@canalrun.com. Finally, CanalRun's postal mail address is: CanalRun, Inc. PO Box 176 Syracuse, NY 13215 |