61 #ifdef DEBUG_TO_FROM_CHAR
62 #define DEBUG_elog_output DEBUG3
75 #include <unicode/ustring.h>
107 #define KeyWord_INDEX_SIZE ('~' - ' ')
108 #define KeyWord_INDEX_FILTER(_c) ((_c) <= ' ' || (_c) >= '~' ? 0 : 1)
114 #define DCH_MAX_ITEM_SIZ 12
115 #define NUM_MAX_ITEM_SIZ 8
161 #define NODE_TYPE_END 1
162 #define NODE_TYPE_ACTION 2
163 #define NODE_TYPE_CHAR 3
164 #define NODE_TYPE_SEPARATOR 4
165 #define NODE_TYPE_SPACE 5
167 #define SUFFTYPE_PREFIX 1
168 #define SUFFTYPE_POSTFIX 2
170 #define CLOCK_24_HOUR 0
171 #define CLOCK_12_HOUR 1
179 "January",
"February",
"March",
"April",
"May",
"June",
"July",
180 "August",
"September",
"October",
"November",
"December", NULL
184 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat", NULL
194 #define ADJUST_YEAR(year, is_interval) ((is_interval) ? (year) : ((year) <= 0 ? -((year) - 1) : (year)))
196 #define A_D_STR "A.D."
197 #define a_d_STR "a.d."
201 #define B_C_STR "B.C."
202 #define b_c_STR "b.c."
223 #define A_M_STR "A.M."
224 #define a_m_STR "a.m."
228 #define P_M_STR "P.M."
229 #define p_m_STR "p.m."
253 {
"XII",
"XI",
"X",
"IX",
"VIII",
"VII",
"VI",
"V",
"IV",
"III",
"II",
"I", NULL};
256 {
"xii",
"xi",
"x",
"ix",
"viii",
"vii",
"vi",
"v",
"iv",
"iii",
"ii",
"i", NULL};
262 static const char *
const rm1[] = {
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX", NULL};
263 static const char *
const rm10[] = {
"X",
"XX",
"XXX",
"XL",
"L",
"LX",
"LXX",
"LXXX",
"XC", NULL};
264 static const char *
const rm100[] = {
"C",
"CC",
"CCC",
"CD",
"D",
"DC",
"DCC",
"DCCC",
"CM", NULL};
270 static const char *
const numTH[] = {
"ST",
"ND",
"RD",
"TH", NULL};
271 static const char *
const numth[] = {
"st",
"nd",
"rd",
"th", NULL};
301 #define NUM_F_DECIMAL (1 << 1)
302 #define NUM_F_LDECIMAL (1 << 2)
303 #define NUM_F_ZERO (1 << 3)
304 #define NUM_F_BLANK (1 << 4)
305 #define NUM_F_FILLMODE (1 << 5)
306 #define NUM_F_LSIGN (1 << 6)
307 #define NUM_F_BRACKET (1 << 7)
308 #define NUM_F_MINUS (1 << 8)
309 #define NUM_F_PLUS (1 << 9)
310 #define NUM_F_ROMAN (1 << 10)
311 #define NUM_F_MULTI (1 << 11)
312 #define NUM_F_PLUS_POST (1 << 12)
313 #define NUM_F_MINUS_POST (1 << 13)
314 #define NUM_F_EEEE (1 << 14)
316 #define NUM_LSIGN_PRE (-1)
317 #define NUM_LSIGN_POST 1
318 #define NUM_LSIGN_NONE 0
324 #define IS_DECIMAL(_f) ((_f)->flag & NUM_F_DECIMAL)
325 #define IS_LDECIMAL(_f) ((_f)->flag & NUM_F_LDECIMAL)
326 #define IS_ZERO(_f) ((_f)->flag & NUM_F_ZERO)
327 #define IS_BLANK(_f) ((_f)->flag & NUM_F_BLANK)
328 #define IS_FILLMODE(_f) ((_f)->flag & NUM_F_FILLMODE)
329 #define IS_BRACKET(_f) ((_f)->flag & NUM_F_BRACKET)
330 #define IS_MINUS(_f) ((_f)->flag & NUM_F_MINUS)
331 #define IS_LSIGN(_f) ((_f)->flag & NUM_F_LSIGN)
332 #define IS_PLUS(_f) ((_f)->flag & NUM_F_PLUS)
333 #define IS_ROMAN(_f) ((_f)->flag & NUM_F_ROMAN)
334 #define IS_MULTI(_f) ((_f)->flag & NUM_F_MULTI)
335 #define IS_EEEE(_f) ((_f)->flag & NUM_F_EEEE)
355 #define DCH_CACHE_OVERHEAD \
356 MAXALIGN(sizeof(bool) + sizeof(int))
357 #define NUM_CACHE_OVERHEAD \
358 MAXALIGN(sizeof(bool) + sizeof(int) + sizeof(NUMDesc))
360 #define DCH_CACHE_SIZE \
361 ((2048 - DCH_CACHE_OVERHEAD) / (sizeof(FormatNode) + sizeof(char)) - 1)
362 #define NUM_CACHE_SIZE \
363 ((1024 - NUM_CACHE_OVERHEAD) / (sizeof(FormatNode) + sizeof(char)) - 1)
365 #define DCH_CACHE_ENTRIES 20
366 #define NUM_CACHE_ENTRIES 20
432 #define ZERO_tmfc(_X) memset(_X, 0, sizeof(TmFromChar))
444 #ifdef DEBUG_TO_FROM_CHAR
445 #define DEBUG_TMFC(_X) \
446 elog(DEBUG_elog_output, "TMFC:\nmode %d\nhh %d\npm %d\nmi %d\nss %d\nssss %d\nd %d\ndd %d\nddd %d\nmm %d\nms: %d\nyear %d\nbc %d\nww %d\nw %d\ncc %d\nj %d\nus: %d\nyysz: %d\nclock: %d", \
447 (_X)->mode, (_X)->hh, (_X)->pm, (_X)->mi, (_X)->ss, (_X)->ssss, \
448 (_X)->d, (_X)->dd, (_X)->ddd, (_X)->mm, (_X)->ms, (_X)->year, \
449 (_X)->bc, (_X)->ww, (_X)->w, (_X)->cc, (_X)->j, (_X)->us, \
450 (_X)->yysz, (_X)->clock)
451 #define DEBUG_TM(_X) \
452 elog(DEBUG_elog_output, "TM:\nsec %d\nyear %d\nmin %d\nwday %d\nhour %d\nyday %d\nmday %d\nnisdst %d\nmon %d\n",\
453 (_X)->tm_sec, (_X)->tm_year,\
454 (_X)->tm_min, (_X)->tm_wday, (_X)->tm_hour, (_X)->tm_yday,\
455 (_X)->tm_mday, (_X)->tm_isdst, (_X)->tm_mon)
457 #define DEBUG_TMFC(_X)
489 #define tmtcTm(_X) (&(_X)->tm)
490 #define tmtcTzn(_X) ((_X)->tzn)
491 #define tmtcFsec(_X) ((_X)->fsec)
494 #define COPY_tm(_DST, _SRC) \
496 (_DST)->tm_sec = (_SRC)->tm_sec; \
497 (_DST)->tm_min = (_SRC)->tm_min; \
498 (_DST)->tm_hour = (_SRC)->tm_hour; \
499 (_DST)->tm_mday = (_SRC)->tm_mday; \
500 (_DST)->tm_mon = (_SRC)->tm_mon; \
501 (_DST)->tm_year = (_SRC)->tm_year; \
502 (_DST)->tm_wday = (_SRC)->tm_wday; \
503 (_DST)->tm_yday = (_SRC)->tm_yday; \
504 (_DST)->tm_gmtoff = (_SRC)->tm_gmtoff; \
508 #define ZERO_tm(_X) \
510 memset(_X, 0, sizeof(*(_X))); \
511 (_X)->tm_mday = (_X)->tm_mon = 1; \
514 #define ZERO_tmtc(_X) \
516 ZERO_tm( tmtcTm(_X) ); \
518 tmtcTzn(_X) = NULL; \
525 #define INVALID_FOR_INTERVAL \
529 (errcode(ERRCODE_INVALID_DATETIME_FORMAT), \
530 errmsg("invalid format specification for an interval value"), \
531 errhint("Intervals are not tied to specific calendar dates."))); \
542 #define DCH_S_FM 0x01
543 #define DCH_S_TH 0x02
544 #define DCH_S_th 0x04
545 #define DCH_S_SP 0x08
546 #define DCH_S_TM 0x10
552 #define S_THth(_s) ((((_s) & DCH_S_TH) || ((_s) & DCH_S_th)) ? 1 : 0)
553 #define S_TH(_s) (((_s) & DCH_S_TH) ? 1 : 0)
554 #define S_th(_s) (((_s) & DCH_S_th) ? 1 : 0)
555 #define S_TH_TYPE(_s) (((_s) & DCH_S_TH) ? TH_UPPER : TH_LOWER)
558 #define S_FM(_s) (((_s) & DCH_S_FM) ? 1 : 0)
559 #define S_SP(_s) (((_s) & DCH_S_SP) ? 1 : 0)
560 #define S_TM(_s) (((_s) & DCH_S_TM) ? 1 : 0)
566 #define TM_SUFFIX_LEN 2
954 -1, -1, -1, -1, -1, -1, -1, -1,
955 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
956 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
957 -1, -1, -1, -1, -1,
DCH_A_D,
DCH_B_C,
DCH_CC,
DCH_DAY, -1,
958 DCH_FF1, -1,
DCH_HH24,
DCH_IDDD,
DCH_J, -1, -1,
DCH_MI, -1,
DCH_OF,
959 DCH_P_M,
DCH_Q,
DCH_RM,
DCH_SSSSS,
DCH_TZH,
DCH_US, -1,
DCH_WW, -1,
DCH_Y_YYY,
960 -1, -1, -1, -1, -1, -1, -1,
DCH_a_d,
DCH_b_c,
DCH_cc,
961 DCH_day, -1,
DCH_ff1, -1,
DCH_hh24,
DCH_iddd,
DCH_j, -1, -1,
DCH_mi,
962 -1,
DCH_of,
DCH_p_m,
DCH_q,
DCH_rm,
DCH_sssss,
DCH_tzh,
DCH_us, -1,
DCH_ww,
978 -1, -1, -1, -1, -1, -1, -1, -1,
979 -1, -1, -1, -1,
NUM_COMMA, -1,
NUM_DEC, -1,
NUM_0, -1,
980 -1, -1, -1, -1, -1, -1, -1,
NUM_9, -1, -1,
981 -1, -1, -1, -1, -1, -1,
NUM_B,
NUM_C,
NUM_D,
NUM_E,
982 NUM_FM,
NUM_G, -1, -1, -1, -1,
NUM_L,
NUM_MI, -1, -1,
983 NUM_PL, -1,
NUM_RN,
NUM_SG,
NUM_TH, -1,
NUM_V, -1, -1, -1,
984 -1, -1, -1, -1, -1, -1, -1, -1,
NUM_b,
NUM_c,
985 NUM_d,
NUM_e,
NUM_fm,
NUM_g, -1, -1, -1, -1,
NUM_l,
NUM_mi,
986 -1, -1,
NUM_pl, -1,
NUM_rn,
NUM_sg,
NUM_th, -1,
NUM_v, -1,
987 -1, -1, -1, -1, -1, -1
1026 #define DCH_DATED 0x01
1027 #define DCH_TIMED 0x02
1028 #define DCH_ZONED 0x04
1047 #ifdef DEBUG_TO_FROM_CHAR
1048 static void dump_index(
const KeyWord *k,
const int *
index);
1049 static void dump_node(
FormatNode *node,
int max);
1052 static const char *
get_th(
char *num,
int type);
1068 const char *
const *array,
1082 char *number,
int input_len,
int to_char_out_pre_spaces,
1106 if ((poz = *(
index + (*
str -
' '))) > -1)
1127 for (s = suf; s->
name != NULL; s++)
1142 return (*
str > 0x20 && *
str < 0x7F &&
1143 !(*
str >=
'A' && *
str <=
'Z') &&
1144 !(*
str >=
'a' && *
str <=
'z') &&
1145 !(*
str >=
'0' && *
str <=
'9'));
1160 (
errcode(ERRCODE_SYNTAX_ERROR),
1161 errmsg(
"\"EEEE\" must be the last pattern used")));
1168 (
errcode(ERRCODE_SYNTAX_ERROR),
1169 errmsg(
"\"9\" must be ahead of \"PR\"")));
1184 (
errcode(ERRCODE_SYNTAX_ERROR),
1185 errmsg(
"\"0\" must be ahead of \"PR\"")));
1211 (
errcode(ERRCODE_SYNTAX_ERROR),
1212 errmsg(
"multiple decimal points")));
1215 (
errcode(ERRCODE_SYNTAX_ERROR),
1216 errmsg(
"cannot use \"V\" and decimal point together")));
1227 (
errcode(ERRCODE_SYNTAX_ERROR),
1228 errmsg(
"cannot use \"S\" twice")));
1231 (
errcode(ERRCODE_SYNTAX_ERROR),
1232 errmsg(
"cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together")));
1251 (
errcode(ERRCODE_SYNTAX_ERROR),
1252 errmsg(
"cannot use \"S\" and \"MI\" together")));
1261 (
errcode(ERRCODE_SYNTAX_ERROR),
1262 errmsg(
"cannot use \"S\" and \"PL\" together")));
1271 (
errcode(ERRCODE_SYNTAX_ERROR),
1272 errmsg(
"cannot use \"S\" and \"SG\" together")));
1280 (
errcode(ERRCODE_SYNTAX_ERROR),
1281 errmsg(
"cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together")));
1298 (
errcode(ERRCODE_SYNTAX_ERROR),
1299 errmsg(
"cannot use \"V\" and decimal point together")));
1306 (
errcode(ERRCODE_SYNTAX_ERROR),
1307 errmsg(
"cannot use \"EEEE\" twice")));
1312 (
errcode(ERRCODE_SYNTAX_ERROR),
1313 errmsg(
"\"EEEE\" is incompatible with other formats"),
1314 errdetail(
"\"EEEE\" may only be used together with digit and decimal point patterns.")));
1333 #ifdef DEBUG_TO_FROM_CHAR
1334 elog(DEBUG_elog_output,
"to_char/number(): run parser");
1395 if (strchr(
"-./,':; ", *
str) == NULL)
1397 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
1398 errmsg(
"invalid datetime format separator: \"%s\"",
1413 else if (*
str ==
'"')
1427 if (*
str ==
'\\' && *(
str + 1))
1445 if (*
str ==
'\\' && *(
str + 1) ==
'"')
1451 else if (isspace((
unsigned char) *
str))
1474 #ifdef DEBUG_TO_FROM_CHAR
1476 #define DUMP_THth(_suf) (S_TH(_suf) ? "TH" : (S_th(_suf) ? "th" : " "))
1477 #define DUMP_FM(_suf) (S_FM(_suf) ? "FM" : " ")
1485 elog(DEBUG_elog_output,
"to_from-char(): DUMP FORMAT");
1487 for (
a = 0, n = node;
a <= max; n++,
a++)
1490 elog(DEBUG_elog_output,
"%d:\t NODE_TYPE_ACTION '%s'\t(%s,%s)",
1493 elog(DEBUG_elog_output,
"%d:\t NODE_TYPE_CHAR '%s'",
1497 elog(DEBUG_elog_output,
"%d:\t NODE_TYPE_END",
a);
1501 elog(DEBUG_elog_output,
"%d:\t unknown NODE!",
a);
1518 int len = strlen(num),
1521 last = *(num + (
len - 1));
1522 if (!isdigit((
unsigned char) last))
1524 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1525 errmsg(
"\"%s\" is not a number", num)));
1531 if ((
len > 1) && (num[
len - 2] ==
'1'))
1575 typedef int32_t (*ICU_Convert_Func) (UChar *
dest, int32_t destCapacity,
1576 const UChar *src, int32_t srcLength,
1578 UErrorCode *pErrorCode);
1581 icu_convert_case(ICU_Convert_Func func,
pg_locale_t mylocale,
1582 UChar **buff_dest, UChar *buff_source, int32_t len_source)
1587 len_dest = len_source;
1588 *buff_dest =
palloc(len_dest *
sizeof(**buff_dest));
1589 status = U_ZERO_ERROR;
1590 len_dest = func(*buff_dest, len_dest, buff_source, len_source,
1592 if (status == U_BUFFER_OVERFLOW_ERROR)
1596 *buff_dest =
palloc(len_dest *
sizeof(**buff_dest));
1597 status = U_ZERO_ERROR;
1598 len_dest = func(*buff_dest, len_dest, buff_source, len_source,
1601 if (U_FAILURE(status))
1603 (
errmsg(
"case conversion failed: %s", u_errorName(status))));
1608 u_strToTitle_default_BI(UChar *
dest, int32_t destCapacity,
1609 const UChar *src, int32_t srcLength,
1611 UErrorCode *pErrorCode)
1613 return u_strToTitle(
dest, destCapacity, src, srcLength,
1614 NULL,
locale, pErrorCode);
1651 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
1652 errmsg(
"could not determine which collation to use for %s function",
1654 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1667 if (mylocale->
provider == COLLPROVIDER_ICU)
1674 len_uchar = icu_to_uchar(&buff_uchar, buff, nbytes);
1675 len_conv = icu_convert_case(u_strToLower, mylocale,
1676 &buff_conv, buff_uchar, len_uchar);
1677 icu_from_uchar(&result, buff_conv, len_conv);
1683 if (mylocale->
provider == COLLPROVIDER_BUILTIN)
1685 const char *src = buff;
1686 size_t srclen = nbytes;
1694 dstsize = srclen + 1;
1698 if (needed + 1 > dstsize)
1701 dstsize = needed + 1;
1704 Assert(needed + 1 == dstsize);
1707 Assert(dst[needed] ==
'\0');
1721 if ((nbytes + 1) > (INT_MAX /
sizeof(
wchar_t)))
1723 (
errcode(ERRCODE_OUT_OF_MEMORY),
1724 errmsg(
"out of memory")));
1727 workspace = (
wchar_t *)
palloc((nbytes + 1) *
sizeof(wchar_t));
1729 char2wchar(workspace, nbytes + 1, buff, nbytes, mylocale);
1731 for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
1732 workspace[curr_char] =
towlower_l(workspace[curr_char], mylocale->
info.
lt);
1739 result =
palloc(result_size);
1741 wchar2char(result, workspace, result_size, mylocale);
1757 for (p = result; *p; p++)
1788 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
1789 errmsg(
"could not determine which collation to use for %s function",
1791 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1804 if (mylocale->
provider == COLLPROVIDER_ICU)
1811 len_uchar = icu_to_uchar(&buff_uchar, buff, nbytes);
1812 len_conv = icu_convert_case(u_strToUpper, mylocale,
1813 &buff_conv, buff_uchar, len_uchar);
1814 icu_from_uchar(&result, buff_conv, len_conv);
1820 if (mylocale->
provider == COLLPROVIDER_BUILTIN)
1822 const char *src = buff;
1823 size_t srclen = nbytes;
1831 dstsize = srclen + 1;
1835 if (needed + 1 > dstsize)
1838 dstsize = needed + 1;
1841 Assert(needed + 1 == dstsize);
1844 Assert(dst[needed] ==
'\0');
1858 if ((nbytes + 1) > (INT_MAX /
sizeof(
wchar_t)))
1860 (
errcode(ERRCODE_OUT_OF_MEMORY),
1861 errmsg(
"out of memory")));
1864 workspace = (
wchar_t *)
palloc((nbytes + 1) *
sizeof(wchar_t));
1866 char2wchar(workspace, nbytes + 1, buff, nbytes, mylocale);
1868 for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
1869 workspace[curr_char] =
towupper_l(workspace[curr_char], mylocale->
info.
lt);
1876 result =
palloc(result_size);
1878 wchar2char(result, workspace, result_size, mylocale);
1894 for (p = result; *p; p++)
1921 while (wbstate->
offset < wbstate->
len &&
1930 size_t prev_offset = wbstate->
offset;
1932 wbstate->
init =
true;
1941 return wbstate->
len;
1954 int wasalnum =
false;
1967 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
1968 errmsg(
"could not determine which collation to use for %s function",
1970 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1983 if (mylocale->
provider == COLLPROVIDER_ICU)
1990 len_uchar = icu_to_uchar(&buff_uchar, buff, nbytes);
1991 len_conv = icu_convert_case(u_strToTitle_default_BI, mylocale,
1992 &buff_conv, buff_uchar, len_uchar);
1993 icu_from_uchar(&result, buff_conv, len_conv);
1999 if (mylocale->
provider == COLLPROVIDER_BUILTIN)
2001 const char *src = buff;
2002 size_t srclen = nbytes;
2011 .prev_alnum =
false,
2017 dstsize = srclen + 1;
2022 if (needed + 1 > dstsize)
2026 wbstate.
init =
false;
2029 dstsize = needed + 1;
2033 Assert(needed + 1 == dstsize);
2049 if ((nbytes + 1) > (INT_MAX /
sizeof(
wchar_t)))
2051 (
errcode(ERRCODE_OUT_OF_MEMORY),
2052 errmsg(
"out of memory")));
2055 workspace = (
wchar_t *)
palloc((nbytes + 1) *
sizeof(wchar_t));
2057 char2wchar(workspace, nbytes + 1, buff, nbytes, mylocale);
2059 for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
2062 workspace[curr_char] =
towlower_l(workspace[curr_char], mylocale->
info.
lt);
2064 workspace[curr_char] =
towupper_l(workspace[curr_char], mylocale->
info.
lt);
2073 result =
palloc(result_size);
2075 wchar2char(result, workspace, result_size, mylocale);
2091 for (p = result; *p; p++)
2123 for (p = result; *p; p++)
2146 for (p = result; *p; p++)
2163 int wasalnum =
false;
2170 for (p = result; *p; p++)
2179 wasalnum = ((
c >=
'A' &&
c <=
'Z') ||
2180 (
c >=
'a' &&
c <=
'z') ||
2181 (
c >=
'0' &&
c <=
'9'));
2228 #define SKIP_THth(ptr, _suf) \
2232 if (*(ptr)) (ptr) += pg_mblen(ptr); \
2233 if (*(ptr)) (ptr) += pg_mblen(ptr); \
2238 #ifdef DEBUG_TO_FROM_CHAR
2251 elog(DEBUG_elog_output,
"TO-FROM_CHAR: Dump KeyWord Index:");
2263 elog(DEBUG_elog_output,
"\t(%d) %c %d",
i,
i + 32,
index[
i]);
2266 elog(DEBUG_elog_output,
"\n\t\tUsed positions: %d,\n\t\tFree positions: %d",
2301 isdigit((
unsigned char) n->
character[0]))
2319 else if (year < 100)
2322 else if (year < 520)
2325 else if (year < 1000)
2337 while (*
str && isspace((
unsigned char) *
str))
2364 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2365 errmsg(
"invalid combination of date conventions"),
2366 errhint(
"Do not mix Gregorian and ISO week date "
2367 "conventions in a formatting template.")));
2387 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2388 errmsg(
"conflicting values for \"%s\" field in formatting string",
2390 errdetail(
"This value contradicts a previous setting "
2391 "for the same field type.")));
2423 const char *
init = *src;
2443 result = strtol(
init, &endptr, 10);
2456 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2457 errmsg(
"source string too short for \"%s\" formatting field",
2459 errdetail(
"Field requires %d characters, but only %d remain.",
2461 errhint(
"If your source string is not fixed-width, "
2462 "try using the \"FM\" modifier.")));
2465 result = strtol(copy, &last, 10);
2468 if (used > 0 && used <
len)
2470 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2471 errmsg(
"invalid value \"%s\" for \"%s\"",
2473 errdetail(
"Field requires %d characters, but only %d could be parsed.",
2475 errhint(
"If your source string is not fixed-width, "
2476 "try using the \"FM\" modifier.")));
2483 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2484 errmsg(
"invalid value \"%s\" for \"%s\"",
2486 errdetail(
"Value must be an integer.")));
2488 if (errno == ERANGE || result < INT_MIN || result > INT_MAX)
2490 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2491 errmsg(
"value for \"%s\" in source string is out of range",
2493 errdetail(
"Value must be in the range %d to %d.",
2494 INT_MIN, INT_MAX)));
2535 unsigned char firstc;
2536 const char *
const *
a;
2547 for (
a = array; *
a != NULL;
a++)
2557 for (p = *
a + 1, n =
name + 1;; p++, n++)
2606 for (
a = array; *
a != NULL;
a++)
2608 int element_len = strlen(*
a);
2610 if (strncmp(
name, *
a, element_len) == 0)
2625 for (
a = array; *
a != NULL;
a++)
2627 char *upper_element;
2628 char *lower_element;
2633 lower_element =
str_tolower(upper_element, strlen(upper_element),
2635 pfree(upper_element);
2636 element_len = strlen(lower_element);
2639 if (strncmp(lower_name, lower_element, element_len) == 0)
2642 pfree(lower_element);
2646 pfree(lower_element);
2680 if (localized_array == NULL)
2694 for (
c = copy; *
c;
c++)
2704 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2705 errmsg(
"invalid value \"%s\" for \"%s\"",
2707 errdetail(
"The given value did not match any of "
2708 "the allowed values for this field.")));
2803 #define DCH_to_char_fsec(frac_fmt, frac_val) \
2804 sprintf(s, frac_fmt, (int) (frac_val)); \
2805 if (S_THth(n->suffix)) \
2806 str_numth(s, s, S_TH_TYPE(n->suffix)); \
2829 #undef DCH_to_char_fsec
2922 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2923 errmsg(
"localized string format value too long")));
2942 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2943 errmsg(
"localized string format value too long")));
2962 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2963 errmsg(
"localized string format value too long")));
2982 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2983 errmsg(
"localized string format value too long")));
3001 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3002 errmsg(
"localized string format value too long")));
3020 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3021 errmsg(
"localized string format value too long")));
3044 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3045 errmsg(
"localized string format value too long")));
3062 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3063 errmsg(
"localized string format value too long")));
3080 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3081 errmsg(
"localized string format value too long")));
3098 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3099 errmsg(
"localized string format value too long")));
3115 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3116 errmsg(
"localized string format value too long")));
3132 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3133 errmsg(
"localized string format value too long")));
3203 if (i <= 99 && i >= -99)
3244 is_interval)) % 1000);
3259 is_interval)) % 100);
3272 is_interval)) % 10);
3290 const char *
const *
months;
3391 while (*s !=
'\0' && isspace((
unsigned char) *s))
3412 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3413 errmsg(
"unmatched format separator \"%c\"",
3473 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3474 errmsg(
"unmatched format character \"%s\"",
3544 out->
ms *=
len == 1 ? 100 :
3560 out->
ff, n, escontext);
3564 out->
us *=
len == 1 ? 100000 :
3595 else if (isalpha((
unsigned char) *s))
3604 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3605 errmsg(
"invalid value \"%s\" for \"%s\"",
3607 errdetail(
"Time zone abbreviation is not recognized.")));
3615 if (*s ==
'+' || *s ==
'-' || *s ==
' ')
3617 out->
tzsign = *s ==
'-' ? -1 : +1;
3622 if (extra_skip > 0 && *(s - 1) ==
'-')
3646 if (*s ==
'+' || *s ==
'-' || *s ==
' ')
3648 out->
tzsign = *s ==
'-' ? -1 : +1;
3653 if (extra_skip > 0 && *(s - 1) ==
'-')
3804 matched = sscanf(s,
"%d,%03d%n", &millennia, &years, &nch);
3807 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3808 errmsg(
"invalid input string for \"Y,YYY\"")));
3809 years += (millennia * 1000);
3880 while (*s !=
'\0' && isspace((
unsigned char) *s))
3896 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3897 errmsg(
"input string is too short for datetime format")));
3899 while (*s !=
'\0' && isspace((
unsigned char) *s))
3904 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
3905 errmsg(
"trailing characters remain in input string after datetime format")));
4042 #ifdef DEBUG_TO_FROM_CHAR
4059 #ifdef DEBUG_TO_FROM_CHAR
4060 elog(DEBUG_elog_output,
"OLD: '%s' AGE: %d", old->
str, old->
age);
4070 #ifdef DEBUG_TO_FROM_CHAR
4149 fmt_len = strlen(fmt_str);
4223 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4224 errmsg(
"timestamp out of range")));
4228 tt.
tm_wday = (thisdate + 1) % 7;
4259 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4260 errmsg(
"timestamp out of range")));
4264 tt.
tm_wday = (thisdate + 1) % 7;
4336 &
tm, &fsec, &ftz, &fprec, NULL, NULL);
4346 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4347 errmsg(
"timestamp out of range")));
4373 &
tm, &fsec, &ftz, NULL, NULL, NULL);
4378 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4379 errmsg(
"date out of range: \"%s\"",
4387 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4388 errmsg(
"date out of range: \"%s\"",
4411 Oid *typid,
int32 *typmod,
int *tz,
4421 &
tm, &fsec, &ftz, &fprec, &flags, escontext))
4424 *typmod = fprec ? fprec : -1;
4448 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4449 errmsg(
"missing time zone in input string for type timestamptz")));
4454 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4455 errmsg(
"timestamptz out of range")));
4459 *typid = TIMESTAMPTZOID;
4468 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4469 errmsg(
"timestamp out of range")));
4473 *typid = TIMESTAMPOID;
4482 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4483 errmsg(
"datetime format is zoned but not timed")));
4492 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4493 errmsg(
"date out of range: \"%s\"",
4502 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4503 errmsg(
"date out of range: \"%s\"",
4531 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4532 errmsg(
"missing time zone in input string for type timetz")));
4537 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4538 errmsg(
"timetz out of range")));
4551 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4552 errmsg(
"time out of range")));
4563 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4564 errmsg(
"datetime format is not dated and not timed")));
4576 int fmt_len = strlen(fmt_str);
4645 bool incache =
false;
4692 #ifdef DEBUG_TO_FROM_CHAR
4740 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4741 errmsg(
"hour \"%d\" is invalid for the 12-hour clock",
4743 errhint(
"Use the 24-hour clock, or give an hour between 1 and 12.")));
4761 if (tmfc.
cc && tmfc.
yysz <= 2)
4826 tmfc.
ddd = (tmfc.
ww - 1) * 7 + 1;
4830 tmfc.
dd = (tmfc.
w - 1) * 7 + 1;
4854 (
errcode(ERRCODE_INVALID_DATETIME_FORMAT),
4855 errmsg(
"cannot calculate day of year without year information")));