[comp.sys.ibm.pc] Date routines in turbo C 1.5.

pa1343@sdcc15.ucsd.edu (John J. Marco) (05/16/89)

I am trying to write an 'ls' program under DOS.  I am using Turbo C
version 1.5 and I use findfirst() and findnext() to get the files.
I am having a problem with file dates.  find... () returns a structure
ffblk such that the time is split into (int ff_ftime, int ff_fdate);
These functions use the DOS interrupt for finding the files.
Does anybody know of any routines for converting these integers to 
UNIX format?  If not, could somebody who knows please email me and tell
me how exactly these integers tell the time.  Turbo C does not seem 
to have any conversion routines and when I print out the integers
I get meaningless numbers which do not look like dates.
I appreciate any and all help.

Please E-mail responses.  Thanks.
+-----------------------------------------+
| John J. Marco -- pa1343@sdcc15.ucsd.edu | 
| ...!uunet!sdcc15.ucsd.edu!pa1343	  |  
+-----------------------------------------+

ddurbin@polyslo.CalPoly.EDU (Daniel A. Durbin) (05/16/89)

In article <1513@sdcc15.ucsd.edu> pa1343@sdcc15.ucsd.edu (John J. Marco) writes:
>I am trying to write an 'ls' program under DOS.  I am using Turbo C
>version 1.5 and I use findfirst() and findnext() to get the files.
>I am having a problem with file dates.  find... () returns a structure
>ffblk such that the time is split into (int ff_ftime, int ff_fdate);
>These functions use the DOS interrupt for finding the files.
>Does anybody know of any routines for converting these integers to 
>UNIX format?  If not, could somebody who knows please email me and tell
>me how exactly these integers tell the time.  Turbo C does not seem 
>to have any conversion routines and when I print out the integers
>I get meaningless numbers which do not look like dates.
>I appreciate any and all help.
>

I whipped this out real quick and it shows how to decode the fdate
and ftime returned by the DOS interrupt used by the TurboC findfirst()
and findnext() functions.  I tested it and it does the same thing as
a DOS dir command.

BEGIN -- cut here -- cut here
--------------------
/* fdate.c by Daniel Durbin  05/15/89 */
/* for TurboC v1.5 */

#include <stdio.h>
#include <dos.h>
#include <dir.h>

void main(int argc, char *argv[])
{
	char s1[9], s2[9];
	struct ffblk ffblk;
	int result;

	if (argc < 2) return;
	result = findfirst(argv[1], &ffblk, FA_ARCH);
	while (result != -1) {
		sprintf(s1, "%02d/%02d/%02d",
			(ffblk.ff_fdate & 0x01e0) / 32,
			(ffblk.ff_fdate & 0x001f),
			(ffblk.ff_fdate & 0xfe00) / 512 + 80
		);
		sprintf(s2, "%02d:%02d:%02d",
			(ffblk.ff_ftime & 0xfc00) / 2048,
			(ffblk.ff_ftime & 0x07e0) / 32,
			(ffblk.ff_ftime & 0x001f)
		);
		printf("%-12s  %6lu  %s  %s\n",
			ffblk.ff_name, ffblk.ff_fsize, s1, s2
		);
		result = findnext(&ffblk);
	}
}
--------------
END -- cut here -- cut here

	Daniel Durbin___________________________________________________
	SysOp: Cygnus X-1 BBS		| CIS: 73447,1744
	(805) 541-8505 (data)		| GEnie: D.DURBIN
	EL major at PolySlo		| ddurbin@polyslo.CalPoly.EDU 

bobmon@iuvax.cs.indiana.edu (RAMontante) (05/17/89)

Peter Norton defines the time and date fields (that findfirst() and
findnext() return) as containing the modification time and date thus:

	time_val = hour*2048 + minutes*32 + seconds/2

	date_val = (year-1980)*512 + month*32 + day

The time and date can be treated as a single unsigned long integer for
purposes of comparison between file timestamps.