From 1c5aec60bb72ec932d68c71d91147e5516796196 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Mon, 29 Nov 1999 23:26:18 +0000 Subject: I finish devel. of Oracle compatible DateTime routines TO_CHAR(), TO_DATE() and PgSQL extension FROM_CHAR(). TO_CHAR() routine allow formating text output with a datetime values: SELECT TO_CHAR('now'::datetime, '"Now is: "HH24:MI:SS'); to_char ---------------- Now is: 21:04:10 FROM_CHAR() routine allow convert text to a datetime: SELECT FROM_CHAR('September 1999 10:20:30', 'FMMonth YYYY HH:MI:SS'); from_char ----------------------------- Wed Sep 01 10:20:30 1999 CEST TO_DATE() is equal with FROM_CHAR(), but output a Date only: SELECT TO_DATE('September 1999 10:20:30', 'FMMonth YYYY HH:MI:SS'); to_date ---------- 09-01-1999 In attache is compressed dir for the contrib. All is prepared, but I'am not sure if Makefile is good (probably yes). Comments & suggestions ? Thomas, thank you for your good advices. Karel ------------------------------------------------------------------------------ Karel Zak http://home.zf.jcu.cz/~zakkr/ --- contrib/dateformat/test/rand_datetime.c | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 contrib/dateformat/test/rand_datetime.c (limited to 'contrib/dateformat/test/rand_datetime.c') diff --git a/contrib/dateformat/test/rand_datetime.c b/contrib/dateformat/test/rand_datetime.c new file mode 100644 index 00000000000..6a96776b9b7 --- /dev/null +++ b/contrib/dateformat/test/rand_datetime.c @@ -0,0 +1,71 @@ + +#include +#include +#include +#include + + +char *month[] = { + "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",NULL +}; + +char *day[] = { "Sun","Mon","Tue","Wed","Thu","Fri","Sat", NULL }; + +int num(FILE *f, int min, int max) +{ + int x, y, one; + + one = x = fgetc(f); + + + if (x < min) + x = min; + else if (x > max) { + while(x > max) + x /= 2; + return x; + } + + do { + y = fgetc(f); + if ((x+y) > max) + return x; + x += y; + } while(--one > 0); + + return x; +} + +int main(int argc, char **argv) +{ + FILE *f; + int count; + + if (argc < 5) { + printf("\nUsage: %s \n", argv[0]); + printf("\n(C) Karel Zak - Zakkr 1999\n\n"); + exit(1); + } + + if ((f = fopen(argv[1], "r")) == NULL) { + perror(argv[1]); + exit(1); + } + + count = atoi(argv[2]); + + for(; count > 0; --count) { + fprintf(stdout, "%s%s %02d %s %02d:%02d:%02d %d%s\n", + argv[3], + day[ num(f, 0, 6) ], + num(f, 1, 28), + month[ num(f, 0, 11) ], + num(f, 0, 23), + num(f, 0, 59), + num(f, 0, 59), + num(f, 0, 9999), + argv[4] + ); + } + exit(0); +} \ No newline at end of file -- cgit v1.2.3