home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name stpfdate -- Format date in national style
- *
- * Synopsis presult = stpfdate(ptarget,year,month,day,pinfo);
- *
- * char *presult The resulting string, or NIL if error.
- * char *ptarget Buffer in which to put the resulting
- * string. It must be long enough to
- * accommodate the result: allow 11 bytes
- * if year exceeds 99, 9 bytes if not.
- * int year Year (0-99 or 1000-2099)
- * int month Month (1-12)
- * int day Day (1-31)
- * COUNTRY_INFO *pinfo
- * Pointer to structure with country info
- *
- * Description This function formats a calendar date according to DOS's
- * information about national style. pinfo must point to a
- * COUNTRY_INFO structure in the format returned by
- * QYGCOUN: in particular, the dfmt and datsep members of
- * the structure must be valid. (This may not be true if
- * the structure was filled by DOS 2.x, or if QYGCOUN
- * reported an error.)
- *
- * If the year value exceeds 99, then four characters will
- * be used for the year; otherwise two characters. For
- * example, in the United States,
- *
- * year = 85, month = 9, day = 26 gives "09-26-85"
- *
- * but
- *
- * year = 1985, month = 9, day = 26 gives "09-26-1985".
- *
- * An illegal date or an unknown value of (pinfo->dfmt) may
- * result in an error. (However, not all illegal dates are
- * detected.) In that case *ptarget will be set to the null
- * string (no characters) and NIL will be returned as the
- * value of the function.
- *
- * Returns presult Pointer to the resulting string, or NIL
- * if error.
- * *ptarget The resulting string, which is the null
- * string if there is an error.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <stdio.h>
-
- #include <bstring.h>
-
- char *stpfdate(ptarget,year,month,day,pinfo)
- register char *ptarget;
- int year,month,day;
- register COUNTRY_INFO *pinfo;
- {
- char *fmt,date_sep;
-
- *ptarget = '\0'; /* Produce null string in case of error */
-
- if (utrange(year,0,2099) || utrange(month,1,12) || utrange(day,1,31))
- return NIL; /* Error: illegal date */
-
- fmt = "%02d%c%02d%c%02d";
- date_sep = (pinfo->datsep)[0];
- switch (pinfo->dfmt)
- {
- case 0: /* USA format */
- sprintf(ptarget,fmt,month,date_sep,
- day,date_sep,
- year);
- break;
- case 1: /* Europe format */
- sprintf(ptarget,fmt,day,date_sep,
- month,date_sep,
- year);
- break;
- case 2: /* Japan format */
- sprintf(ptarget,fmt,year,date_sep,
- month,date_sep,
- day);
- break;
- default: /* Error: unknown date format */
- return NIL;
- }
-
- return ptarget;
- }