*** ./src/backend/utils/adt/formatting.c.orig 2006-11-18 16:22:59.000000000 -0200 --- ./src/backend/utils/adt/formatting.c 2006-11-20 21:50:02.000000000 -0200 *************** *** 73,79 **** #include #include #include ! #include #include "utils/builtins.h" #include "utils/date.h" --- 73,79 ---- #include #include #include ! #include #include "utils/builtins.h" #include "utils/date.h" *************** *** 83,90 **** #include "utils/numeric.h" #include "utils/pg_locale.h" - #define _(x) gettext((x)) - /* ---------- * Routines type * ---------- --- 83,88 ---- *************** *** 163,169 **** /* ---------- * Full months - * This needs to be NLS-localized someday. * ---------- */ static char *months_full[] = { --- 161,166 ---- *************** *** 942,951 **** static NUMCacheEntry *NUM_cache_getnew(char *str); static void NUM_cache_remove(NUMCacheEntry *ent); - static char *localize_month_full(int index); - static char *localize_month(int index); - static char *localize_day_full(int index); - static char *localize_day(int index); /* ---------- * Fast sequential search, use index for data selection which --- 939,944 ---- *************** *** 2074,2079 **** --- 2067,2085 ---- struct pg_tm *tm = NULL; TmFromChar *tmfc = NULL; TmToChar *tmtc = NULL; + char *save_loc = NULL; + char *lct = NULL; + + /* + * Set the LC_TIME only to do some operation (strftime) and then + * set it back. See pg_locale.c for explanations. + */ + if (S_TM(suf)) + { + save_loc = setlocale(LC_TIME, NULL); + lct = pg_get_lc_time(); + setlocale(LC_TIME, lct); + } if (is_to_char) { *************** *** 2189,2197 **** if (!tm->tm_mon) return -1; if (S_TM(suf)) ! strcpy(workbuff, localize_month_full(tm->tm_mon - 1)); else strcpy(workbuff, months_full[tm->tm_mon - 1]); sprintf(inout, "%*s", (S_FM(suf) || S_TM(suf)) ? 0 : -9, str_toupper(workbuff)); return strlen(p_inout); --- 2195,2214 ---- if (!tm->tm_mon) return -1; if (S_TM(suf)) ! { ! /* ! * tm_mon in 'pg_tm struct' based on one, but rather POSIX 'tm struct' based on zero. ! * See notes at the top of this file. ! */ ! tm->tm_mon = tm->tm_mon - 1; ! strftime(workbuff, sizeof(workbuff), "%B", (struct tm *) tm); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { strcpy(workbuff, months_full[tm->tm_mon - 1]); + } sprintf(inout, "%*s", (S_FM(suf) || S_TM(suf)) ? 0 : -9, str_toupper(workbuff)); return strlen(p_inout); *************** *** 2200,2208 **** if (!tm->tm_mon) return -1; if (S_TM(suf)) ! sprintf(inout, "%*s", 0, localize_month_full(tm->tm_mon - 1)); else sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, months_full[tm->tm_mon - 1]); return strlen(p_inout); case DCH_month: --- 2217,2238 ---- if (!tm->tm_mon) return -1; if (S_TM(suf)) ! { ! /* ! * tm_mon in 'pg_tm struct' based on one, but rather POSIX 'tm struct' based on zero. ! * See notes at the top of this file. ! */ ! tm->tm_mon = tm->tm_mon - 1; ! strftime(inout, 32, "%B", (struct tm *) tm); ! /* capitalize output */ ! inout[0] = pg_toupper((unsigned char) inout[0]); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, months_full[tm->tm_mon - 1]); + } return strlen(p_inout); case DCH_month: *************** *** 2210,2218 **** if (!tm->tm_mon) return -1; if (S_TM(suf)) ! sprintf(inout, "%*s", 0, localize_month_full(tm->tm_mon - 1)); else sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, months_full[tm->tm_mon - 1]); *inout = pg_tolower((unsigned char) *inout); return strlen(p_inout); --- 2240,2259 ---- if (!tm->tm_mon) return -1; if (S_TM(suf)) ! { ! /* ! * tm_mon in 'pg_tm struct' based on one, but rather POSIX 'tm struct' based on zero. ! * See notes at the top of this file. ! */ ! tm->tm_mon = tm->tm_mon - 1; ! strftime(inout, 32, "%B", (struct tm *) tm); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, months_full[tm->tm_mon - 1]); + } *inout = pg_tolower((unsigned char) *inout); return strlen(p_inout); *************** *** 2221,2229 **** if (!tm->tm_mon) return -1; if (S_TM(suf)) ! strcpy(inout, localize_month(tm->tm_mon - 1)); else strcpy(inout, months[tm->tm_mon - 1]); str_toupper(inout); return strlen(p_inout); --- 2262,2281 ---- if (!tm->tm_mon) return -1; if (S_TM(suf)) ! { ! /* ! * tm_mon in 'pg_tm struct' based on one, but rather POSIX 'tm struct' based on zero. ! * See notes at the top of this file. ! */ ! tm->tm_mon = tm->tm_mon - 1; ! strftime(inout, 32, "%b", (struct tm *) tm); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { strcpy(inout, months[tm->tm_mon - 1]); + } str_toupper(inout); return strlen(p_inout); *************** *** 2232,2240 **** if (!tm->tm_mon) return -1; if (S_TM(suf)) ! strcpy(inout, localize_month(tm->tm_mon - 1)); else strcpy(inout, months[tm->tm_mon - 1]); return strlen(p_inout); case DCH_mon: --- 2284,2305 ---- if (!tm->tm_mon) return -1; if (S_TM(suf)) ! { ! /* ! * tm_mon in 'pg_tm struct' based on one, but rather POSIX 'tm struct' based on zero. ! * See notes at the top of this file. ! */ ! tm->tm_mon = tm->tm_mon - 1; ! strftime(inout, 32, "%b", (struct tm *) tm); ! /* capitalize output */ ! inout[0] = pg_toupper((unsigned char) inout[0]); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { strcpy(inout, months[tm->tm_mon - 1]); + } return strlen(p_inout); case DCH_mon: *************** *** 2242,2250 **** if (!tm->tm_mon) return -1; if (S_TM(suf)) ! strcpy(inout, localize_month(tm->tm_mon - 1)); else strcpy(inout, months[tm->tm_mon - 1]); *inout = pg_tolower((unsigned char) *inout); return strlen(p_inout); --- 2307,2326 ---- if (!tm->tm_mon) return -1; if (S_TM(suf)) ! { ! /* ! * tm_mon in 'pg_tm struct' based on one, but rather POSIX 'tm struct' based on zero. ! * See notes at the top of this file. ! */ ! tm->tm_mon = tm->tm_mon - 1; ! strftime(inout, 32, "%b", (struct tm *) tm); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { strcpy(inout, months[tm->tm_mon - 1]); + } *inout = pg_tolower((unsigned char) *inout); return strlen(p_inout); *************** *** 2273,2324 **** case DCH_DAY: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! strcpy(workbuff, localize_day_full(tm->tm_wday)); else strcpy(workbuff, days[tm->tm_wday]); sprintf(inout, "%*s", (S_FM(suf) || S_TM(suf)) ? 0 : -9, str_toupper(workbuff)); return strlen(p_inout); case DCH_Day: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! sprintf(inout, "%*s", 0, localize_day_full(tm->tm_wday)); else sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, days[tm->tm_wday]); return strlen(p_inout); case DCH_day: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! sprintf(inout, "%*s", 0, localize_day_full(tm->tm_wday)); else sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, days[tm->tm_wday]); *inout = pg_tolower((unsigned char) *inout); return strlen(p_inout); case DCH_DY: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! strcpy(inout, localize_day(tm->tm_wday)); else strcpy(inout, days_short[tm->tm_wday]); str_toupper(inout); return strlen(p_inout); case DCH_Dy: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! strcpy(inout, localize_day(tm->tm_wday)); else strcpy(inout, days_short[tm->tm_wday]); return strlen(p_inout); case DCH_dy: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! strcpy(inout, localize_day(tm->tm_wday)); else strcpy(inout, days_short[tm->tm_wday]); *inout = pg_tolower((unsigned char) *inout); return strlen(p_inout); --- 2349,2440 ---- case DCH_DAY: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! { ! strftime(workbuff, sizeof(workbuff), "%A", (struct tm *) tm); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { strcpy(workbuff, days[tm->tm_wday]); + } sprintf(inout, "%*s", (S_FM(suf) || S_TM(suf)) ? 0 : -9, str_toupper(workbuff)); return strlen(p_inout); case DCH_Day: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! { ! strftime(inout, 32, "%A", (struct tm *) tm); ! /* capitalize output */ ! inout[0] = pg_toupper((unsigned char) inout[0]); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, days[tm->tm_wday]); + } return strlen(p_inout); case DCH_day: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! { ! strftime(inout, 32, "%A", (struct tm *) tm); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, days[tm->tm_wday]); + } *inout = pg_tolower((unsigned char) *inout); return strlen(p_inout); case DCH_DY: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! { ! strftime(inout, 32, "%a", (struct tm *) tm); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { strcpy(inout, days_short[tm->tm_wday]); + } str_toupper(inout); return strlen(p_inout); case DCH_Dy: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! { ! strftime(inout, 32, "%a", (struct tm *) tm); ! /* capitalize output */ ! inout[0] = pg_toupper((unsigned char) inout[0]); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { strcpy(inout, days_short[tm->tm_wday]); + } return strlen(p_inout); case DCH_dy: INVALID_FOR_INTERVAL; if (S_TM(suf)) ! { ! strftime(inout, 32, "%a", (struct tm *) tm); ! /* set it back; see comments in pg_locale.c */ ! setlocale(LC_TIME, save_loc); ! } else + { strcpy(inout, days_short[tm->tm_wday]); + } *inout = pg_tolower((unsigned char) *inout); return strlen(p_inout); *************** *** 2860,3026 **** return res; } - static char * - localize_month_full(int index) - { - char *m = NULL; - - switch (index) - { - case 0: - m = _("January"); - break; - case 1: - m = _("February"); - break; - case 2: - m = _("March"); - break; - case 3: - m = _("April"); - break; - case 4: - m = _("May"); - break; - case 5: - m = _("June"); - break; - case 6: - m = _("July"); - break; - case 7: - m = _("August"); - break; - case 8: - m = _("September"); - break; - case 9: - m = _("October"); - break; - case 10: - m = _("November"); - break; - case 11: - m = _("December"); - break; - } - - return m; - } - - static char * - localize_month(int index) - { - char *m = NULL; - - switch (index) - { - case 0: - m = _("Jan"); - break; - case 1: - m = _("Feb"); - break; - case 2: - m = _("Mar"); - break; - case 3: - m = _("Apr"); - break; - case 4: - m = _("May"); - break; - case 5: - m = _("Jun"); - break; - case 6: - m = _("Jul"); - break; - case 7: - m = _("Aug"); - break; - case 8: - m = _("Sep"); - break; - case 9: - m = _("Oct"); - break; - case 10: - m = _("Nov"); - break; - case 11: - m = _("Dec"); - break; - } - - return m; - } - - static char * - localize_day_full(int index) - { - char *d = NULL; - - switch (index) - { - case 0: - d = _("Sunday"); - break; - case 1: - d = _("Monday"); - break; - case 2: - d = _("Tuesday"); - break; - case 3: - d = _("Wednesday"); - break; - case 4: - d = _("Thursday"); - break; - case 5: - d = _("Friday"); - break; - case 6: - d = _("Saturday"); - break; - } - - return d; - } - - static char * - localize_day(int index) - { - char *d = NULL; - - switch (index) - { - case 0: - d = _("Sun"); - break; - case 1: - d = _("Mon"); - break; - case 2: - d = _("Tue"); - break; - case 3: - d = _("Wed"); - break; - case 4: - d = _("Thu"); - break; - case 5: - d = _("Fri"); - break; - case 6: - d = _("Sat"); - break; - } - - return d; - } /**************************************************************************** * Public routines --- 2976,2981 ---- *** ./src/backend/utils/adt/pg_locale.c.orig 2006-11-19 21:13:10.000000000 -0200 --- ./src/backend/utils/adt/pg_locale.c 2006-11-20 21:33:34.000000000 -0200 *************** *** 26,33 **** * required information obtained from localeconv(), and set them back. * The cached information is only used by the formatting functions * (to_char, etc.) and the money type. For the user, this should all be ! * transparent. (Actually, LC_TIME doesn't do anything at all right ! * now.) * * !!! NOW HEAR THIS !!! * --- 26,32 ---- * required information obtained from localeconv(), and set them back. * The cached information is only used by the formatting functions * (to_char, etc.) and the money type. For the user, this should all be ! * transparent. * * !!! NOW HEAR THIS !!! * *************** *** 425,427 **** --- 424,435 ---- CurrentLocaleConvValid = true; return &CurrentLocaleConv; } + + /* + * Return the LC_TIME information + */ + char * + pg_get_lc_time(void) + { + return locale_time; + } *** ./src/include/utils/pg_locale.h.orig 2006-11-19 22:07:21.000000000 -0200 --- ./src/include/utils/pg_locale.h 2006-11-19 22:08:22.000000000 -0200 *************** *** 42,45 **** --- 42,47 ---- */ extern struct lconv *PGLC_localeconv(void); + extern char *pg_get_lc_time(void); + #endif /* _PG_LOCALE_ */