PostgreSQL Source Code  git master
compat_informix-rfmtdate.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <ecpg_informix.h>
#include <stdio.h>
#include <stdlib.h>
#include <pgtypes_error.h>
#include <sqltypes.h>
Include dependency graph for compat_informix-rfmtdate.c:

Go to the source code of this file.

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 

Functions

static void check_return (int ret)
 
static void date_test_strdate (const char *input)
 
static void date_test_defmt (const char *fmt, const char *input)
 
static void date_test_fmt (date d, const char *fmt)
 
int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 9 of file compat_informix-rfmtdate.c.

Function Documentation

◆ check_return()

static void check_return ( int  ret)
static

Definition at line 165 of file compat_informix-rfmtdate.c.

166 {
167  switch(ret)
168  {
170  printf("(ECPG_INFORMIX_ENOTDMY)");
171  break;
173  printf("(ECPG_INFORMIX_ENOSHORTDATE)");
174  break;
176  printf("(ECPG_INFORMIX_BAD_DAY)");
177  break;
179  printf("(ECPG_INFORMIX_BAD_MONTH)");
180  break;
181  default:
182  printf("(unknown ret: %d)", ret);
183  break;
184  }
185  printf("\n");
186 }
#define ECPG_INFORMIX_ENOTDMY
Definition: ecpg_informix.h:25
#define ECPG_INFORMIX_BAD_DAY
Definition: ecpg_informix.h:21
#define ECPG_INFORMIX_BAD_MONTH
Definition: ecpg_informix.h:20
#define ECPG_INFORMIX_ENOSHORTDATE
Definition: ecpg_informix.h:22
#define printf(...)
Definition: port.h:244

References ECPG_INFORMIX_BAD_DAY, ECPG_INFORMIX_BAD_MONTH, ECPG_INFORMIX_ENOSHORTDATE, ECPG_INFORMIX_ENOTDMY, and printf.

Referenced by date_test_defmt(), date_test_fmt(), and date_test_strdate().

◆ date_test_defmt()

static void date_test_defmt ( const char *  fmt,
const char *  input 
)
static

Definition at line 52 of file compat_informix-rfmtdate.c.

53 {
54  static int i;
55  char dbuf[11];
56  date d;
57  int q, r;
58 
59  r = rdefmtdate(&d, fmt, input);
60  printf("r: %d ", r);
61  if (r == 0)
62  {
63  q = rdatestr(d, dbuf);
64  printf("q: %d ", q);
65  if (q == 0)
66  {
67  printf("date %d: %s\n", i++, dbuf);
68  }
69  else
70  printf("\n");
71  }
72  else
73  check_return(r);
74 }
static void check_return(int ret)
FILE * input
int rdatestr(date d, char *str)
Definition: informix.c:508
int rdefmtdate(date *d, const char *fmt, const char *str)
Definition: informix.c:553
int i
Definition: isn.c:73
static void const char * fmt
long date
Definition: pgtypes_date.h:9

References check_return(), fmt, i, input, printf, rdatestr(), and rdefmtdate().

Referenced by main().

◆ date_test_fmt()

static void date_test_fmt ( date  d,
const char *  fmt 
)
static

Definition at line 77 of file compat_informix-rfmtdate.c.

78 {
79  static int i;
80  char buf[200];
81  int r;
82 
83  r = rfmtdate(d, fmt, buf);
84  printf("r: %d ", r);
85  if (r != 0)
86  check_return(r);
87  else
88  printf("date: %d: %s\n", i++, buf);
89 }
int rfmtdate(date d, const char *fmt, char *str)
Definition: informix.c:579
static char * buf
Definition: pg_test_fsync.c:73

References buf, check_return(), fmt, i, printf, and rfmtdate().

Referenced by main().

◆ date_test_strdate()

static void date_test_strdate ( const char *  input)
static

Definition at line 27 of file compat_informix-rfmtdate.c.

28 {
29  static int i;
30  date d;
31  int r, q;
32  char dbuf[11];
33 
34  r = rstrdate(input, &d);
35  printf("r: %d ", r);
36  if (r == 0)
37  {
38  q = rdatestr(d, dbuf);
39  printf("q: %d ", q);
40  if (q == 0)
41  {
42  printf("date %d: %s\n", i++, dbuf);
43  }
44  else
45  printf("\n");
46  }
47  else
48  check_return(r);
49 }
int rstrdate(const char *str, date *d)
Definition: informix.c:529

References check_return(), i, input, printf, rdatestr(), and rstrdate().

Referenced by main().

◆ main()

int main ( void  )

Definition at line 93 of file compat_informix-rfmtdate.c.

94 {
95  short mdy[3] = { 11, 23, 1959 };
96  char dbuf[11];
97  date d;
98  int r;
99 
100  ECPGdebug(1, stderr);
101 
102  r = rmdyjul(mdy, &d);
103  printf("create: r: %d\n", r);
104  if (r == 0)
105  {
106  rdatestr(d, dbuf);
107  printf("date: %s\n", dbuf);
108  }
109 
110  /* input mask is mmddyyyy */
111  date_test_strdate("12031994");
112  date_test_strdate("9.6.1994");
113 
114  date_test_fmt(d, "mmddyy");
115  date_test_fmt(d, "ddmmyy");
116  date_test_fmt(d, "yymmdd");
117  date_test_fmt(d, "yy/mm/dd");
118  date_test_fmt(d, "yy mm dd");
119  date_test_fmt(d, "yy.mm.dd");
120  date_test_fmt(d, ".mm.yyyy.dd.");
121  date_test_fmt(d, "mmm. dd, yyyy");
122  date_test_fmt(d, "mmm dd yyyy");
123  date_test_fmt(d, "yyyy dd mm");
124  date_test_fmt(d, "ddd, mmm. dd, yyyy");
125  date_test_fmt(d, "(ddd) mmm. dd, yyyy");
126 
127  date_test_defmt("ddmmyy", "21-2-54");
128  date_test_defmt("ddmmyy", "2-12-54");
129  date_test_defmt("ddmmyy", "20111954");
130  date_test_defmt("ddmmyy", "130464");
131  date_test_defmt("mmm.dd.yyyy", "MAR-12-1967");
132  date_test_defmt("yy/mm/dd", "1954, February 3rd");
133  date_test_defmt("mmm.dd.yyyy", "041269");
134  date_test_defmt("yy/mm/dd", "In the year 2525, in the month of July, mankind will be alive on the 28th day");
135  date_test_defmt("dd-mm-yy", "I said on the 28th of July in the year 2525");
136  date_test_defmt("mmm.dd.yyyy", "9/14/58");
137  date_test_defmt("yy/mm/dd", "47/03/29");
138  date_test_defmt("mmm.dd.yyyy", "oct 28 1975");
139  date_test_defmt("mmddyy", "Nov 14th, 1985");
140  /* ok: still contains dd mm yy */
141  date_test_defmt("bladdfoommbaryybong", "20/11/1954");
142  /* 1994 is not a leap year, it accepts the date as 01-03-1994 */
143  date_test_defmt("ddmmyy", "29-02-1994");
144 
145  /* ECPG_INFORMIX_ENOTDMY, need "dd", "mm" and "yy" */
146  date_test_defmt("dmy", "20/11/1954");
147 
148  /* ECPG_INFORMIX_ENOSHORTDATE */
149  date_test_defmt("ddmmyy", "21254");
150  date_test_defmt("ddmmyy", " 21254 ");
151 
152  /* ECPG_INFORMIX_BAD_DAY */
153  date_test_defmt("ddmmyy", "320494");
154 
155  /* ECPG_INFORMIX_BAD_MONTH */
156  date_test_defmt("mm-yyyy-dd", "13-1993-21");
157 
158  /* ECPG_INFORMIX_BAD_YEAR */
159  /* ??? */
160 
161  return 0;
162 }
static void date_test_fmt(date d, const char *fmt)
static void date_test_defmt(const char *fmt, const char *input)
static void date_test_strdate(const char *input)
#define ECPGdebug(X, Y)
int rmdyjul(short *mdy, date *d)
Definition: informix.c:592

References date_test_defmt(), date_test_fmt(), date_test_strdate(), ECPGdebug, printf, rdatestr(), and rmdyjul().