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

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