home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
MISC
/
FTSER10.ZIP
/
ADTDV2.ZIP
/
howto.txt
< prev
next >
Wrap
Text File
|
1997-01-26
|
6KB
|
150 lines
This is the second and probably last version of td.lib.
A few minor tweaks were made to enhance code efficiency.
If you have not read the "readme.txt" file, please take a minute to
do so, it contains system requirements and other important info.
The main reason for this library is to make working with time and dates
as flexible and easy as possible. It is targeted toward the beginning
C programmer. However, anyone that has had to do much time and date progr
amming will appreciate it's simplicity.
It provides three main advantages over the ANSI standard
functions:
1. It is easier to use.
2. It provides accurate date and time calculations with greater
flexibility for practical work.
3. Dates and times from Jan. 1, 1 A.D. are allowed.
I have received some questions about whether Unix systems have
the same time/date draw-backs as MSDOS does. The answer is YES.
More precisely, it is not the particular system your working with
that makes time and date routines a pain to code, but rather it is
the way the ANSI committee has defined the various time/date functions.
Therefore, if your using ANSI compliant C code, which to my knowledge
just about all Unix systems do, you will encounter the same difficulties
previously mentioned on a Unix system.
Another question was "Can td.lib be used on a Unix system?".
The answer is no, not directly.
The ".lib" (short for library) extension is for MSDOS only.
Unix uses "archives" that have a ".a" extension. The functions
in td.lib will work on a Unix system but you will either have to
get the source code to create a Unix archive (library) yourself
or obtain td.lib in a Unix format. (Which I have not released.)
I will provide the source code for td.lib, along with instructions
for creating a Unix version of td.lib, or create a Unix td.a
for those who need it for a limited time.
(See "readme.txt" for contact info.)
Here are the basics for using the library:
To work with the current time and date settings on your system, simply
declare a pointer to a tdtype like this:
tdtype *date;
Now to initialize the date and time fields with the current data, make
this call:
date = TimeDate();
That's it. The structure that is created is like the tm structure defined
in the time.h header file except only the first six fields are used or
needed.
You can now make function calls or print out any of the fields by making
a call to TDFormat();
To use TDFormat(), you will need to declare an output char array of the
size you need to hold all the characters in your output.
The arguments to the function are:
TDFormat(tdtype *, char *, int, char *);
For example to print out the current time and date you could use these
declarations and statements:
tdtype *date;
char *output[40];
date = TimeDate();
TDFormat(date, output, 40, "The current date and time is: %x %I %p ");
This is very similar to using strftime(). In fact I've made everything
as close to the ANSI standard as possible but without some of its
limitations. To do this I had to completely rewrite the format specifiers
so that they would work with more date/time information. I also rearranged
the order of the parameters to strftime() to make them easier to remember.
To create multiple date/time structures make calls to CreateDate().
Then you can prompt the user for the date/time data and load the data
into the structure with LoadDate(). Any structures that you create in
this way should be "freed" when you are finished with them by calling
FreeDate() to return system memory. e.g. FreeDate(&date);
As with any dynamically allocated type, remember to "free" it only once
and not use it's pointer again until you reallocate memory!
Note: do not free any pointer used with TimeDate()! This function uses
the current system settings and works with the standard tm structure.
Look at the two sample files "cal.c" and "demo.c" to see examples of
using the functions. Everything is really very easy to use.
See the header file "datelib.h" for function descriptions, function
arguments, and return types.
To compile your file use either bcc or tcc:
bcc yourfile.c td.lib
If your turboc.cfg file does not have the small memory model (-ms) set
then use:
bcc -ms yourfile.c td.lib
(Don't forget to include "datelib.h" in your main source file.)
Microsoft and Watcom compilers can also be used in the small memory
model.
/*---------------------------[ Format options ]----------------------------*
%n Two-digit hour and minutes with AM or PM
%r Day, month, and year with full names
%% Displays the % character
%a Abbreviated weekday name
%A Full weekday name
%b Abbreviated month name
%B Full month name
%c Date and time (Unix style yuk!)
%d Two-digit day of month (01 - 31)
%H Two-digit hour (00 - 23)
%I Two-digit hour (01 - 12)
%M 2-digit minute (00 - 59)
%p AM or PM
%S Two-digit second (00 - 59)
%j Three-digit day of year (001 - 366)
%m Two-digit month as a decimal number (1 - 12)
%U Two-digit week number where Sunday is the first day of the week (00 - 53)
%w Weekday where 0 is Sunday (0 - 6)
%W Two-digit week number where Monday is the first day of the week (00 - 53)
%x Date
%X Time
%y Two-digit year without century (01 to 99)
%Y Year with century
%Z Time zone name, or no characters if no time zone
*-------------------------------------------------------------------------*/