home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / word2x0a.zip / source / usdate.cc < prev    next >
C/C++ Source or Header  |  1997-04-13  |  1KB  |  63 lines

  1. /* $Id: usdate.cc,v 1.5 1997/04/13 15:46:48 dps Exp $ */
  2. /* Date formatter for the UK */
  3.  
  4. #include "config.h"
  5.  
  6. #ifdef TM_IN_SYS_TIME
  7. #include <sys/time.h>
  8. #else
  9. #include <time.h>
  10. #endif
  11.  
  12. #ifdef HAVE_STRING_H
  13. #include <string.h>
  14. #else /* do not have sting.h */
  15. #include <strings.h>
  16. #endif /* HAVE_STRING_H */
  17.  
  18. #define __EXCLUDE_READER_CLASSES
  19. #include "lib.h"
  20.  
  21. char *us_date(time_t when)
  22. {
  23.     static const char *months[]=
  24.     {
  25.     "January", "February", "March", "April",
  26.     "May", "June", "July", "August",
  27.     "September", "October", "November", "December",
  28.     };
  29.  
  30.     struct tm *tim;
  31.     char date_buf[200];
  32.     const char *postfix;
  33.     
  34.     tim=localtime(&when);
  35.     switch (tim->tm_mday % 10)
  36.     {
  37.     case 1:
  38.     postfix="st";
  39.     break;
  40.  
  41.     case 2:
  42.     postfix="nd";
  43.     break;
  44.  
  45.     case 3:
  46.     postfix="rd";
  47.     break;
  48.  
  49.     default:
  50.     postfix="th";
  51.     break;
  52.     }
  53.     if (tim->tm_mday > 10 && tim->tm_mday < 14) postfix="th";
  54.  
  55.     sprintf(date_buf, "%s %d%s, %d", months[tim->tm_mon],
  56.         tim->tm_mday, postfix, 1900+tim->tm_year);
  57.     
  58.     return strdup(date_buf);
  59. }
  60.  
  61.  
  62.     
  63.