summaryrefslogtreecommitdiff
path: root/support/word2x/usdate.cc
blob: 1ecdd3ad512dfe900b814da776a884df24d47ee5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* $Id: usdate.cc,v 1.5 1997/04/13 15:46:48 dps Exp $ */
/* Date formatter for the UK */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#ifdef TM_IN_SYS_TIME
#include <sys/time.h>
#else
#include <time.h>
#endif

#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */

#define __EXCLUDE_READER_CLASSES
#include "lib.h"

char *us_date(time_t when)
{
    static const char *months[]=
    {
	"January", "February", "March", "April",
	"May", "June", "July", "August",
	"September", "October", "November", "December",
    };

    struct tm *tim;
    char date_buf[200];
    const char *postfix;
    
    tim=localtime(&when);
    switch (tim->tm_mday % 10)
    {
    case 1:
	postfix="st";
	break;

    case 2:
	postfix="nd";
	break;

    case 3:
	postfix="rd";
	break;

    default:
	postfix="th";
	break;
    }
    if (tim->tm_mday > 10 && tim->tm_mday < 14) postfix="th";

    sprintf(date_buf, "%s %d%s, %d", months[tim->tm_mon],
	    tim->tm_mday, postfix, 1900+tim->tm_year);
    
    return strdup(date_buf);
}