59 char **ptr = (endptr != NULL) ? endptr : &realptr;
61 bool EuroDates =
false;
107 bool EuroDates =
false;
144 return (
int) (dDate +
date2j(2000, 1, 1) + 1) % 7;
154 *d =
date2j(ts.tm_year, ts.tm_mon, ts.tm_mday) -
date2j(2000, 1, 1);
157 #define PGTYPES_DATE_NUM_MAX_DIGITS 20
160 #define PGTYPES_FMTDATE_DAY_DIGITS_LZ 1
161 #define PGTYPES_FMTDATE_DOW_LITERAL_SHORT 2
162 #define PGTYPES_FMTDATE_MONTH_DIGITS_LZ 3
163 #define PGTYPES_FMTDATE_MONTH_LITERAL_SHORT 4
164 #define PGTYPES_FMTDATE_YEAR_DIGITS_SHORT 5
165 #define PGTYPES_FMTDATE_YEAR_DIGITS_LONG 6
212 strcpy(outbuf, fmtstring);
218 for (
i = 0; mapping[
i].format != NULL;
i++)
220 while ((start_pattern = strstr(outbuf, mapping[
i].
format)) != NULL)
222 switch (mapping[
i].component)
256 switch (replace_type)
260 memcpy(start_pattern, replace_val.
str_val,
273 memcpy(start_pattern, t, strlen(t));
285 memcpy(start_pattern, t, strlen(t));
297 memcpy(start_pattern, t, strlen(t));
328 #define PGTYPES_DATE_MONTH_MAXLENGTH 20
337 int token_values[3] = {-1, -1, -1};
338 char *fmt_token_order;
357 fmt_ystart = strstr(
fmt,
"yy");
358 fmt_mstart = strstr(
fmt,
"mm");
359 fmt_dstart = strstr(
fmt,
"dd");
361 if (!fmt_ystart || !fmt_mstart || !fmt_dstart)
367 if (fmt_ystart < fmt_mstart)
370 if (fmt_dstart < fmt_ystart)
373 fmt_token_order =
"dym";
375 else if (fmt_dstart > fmt_mstart)
378 fmt_token_order =
"ymd";
383 fmt_token_order =
"ydm";
390 if (fmt_dstart < fmt_mstart)
393 fmt_token_order =
"dmy";
395 else if (fmt_dstart > fmt_ystart)
398 fmt_token_order =
"myd";
403 fmt_token_order =
"mdy";
421 if (!isdigit((
unsigned char)
str[
i]))
433 if (
i != 8 &&
i != 6)
457 if (fmt_token_order[0] ==
'y')
463 else if (fmt_token_order[1] ==
'y')
483 for (
i = 0;
i < 3;
i++)
488 start_pos += frag_length[0];
490 start_pos += frag_length[1];
492 strncpy(str_copy + target_pos,
str + start_pos,
494 target_pos += frag_length[
i];
497 str_copy[target_pos] =
' ';
501 str_copy[target_pos] =
'\0';
510 for (
i = 0; str_copy[
i];
i++)
511 str_copy[
i] = (
char)
pg_tolower((
unsigned char) str_copy[
i]);
517 for (
i = 0;
i < strlen(str_copy);
i++)
519 if (!isdigit((
unsigned char) str_copy[
i]) && reading_digit)
522 token[token_count][1] =
i - 1;
526 else if (isdigit((
unsigned char) str_copy[
i]) && !reading_digit)
529 token[token_count][0] =
i;
540 token[token_count][1] =
i - 1;
556 if (token_count != 3)
569 if (!month_lower_tmp)
581 if (!month_lower_tmp[
j])
587 if ((start_pos = strstr(str_copy, month_lower_tmp)))
589 offset = start_pos - str_copy;
595 if (offset <
token[0][0])
603 else if (offset <
token[1][0])
611 token[token_count][0] = offset;
612 token[token_count][1] = offset + strlen(month_lower_tmp) - 1;
618 token_values[token_count] =
i + 1;
630 if (
list[
i + 1] == NULL)
639 free(month_lower_tmp);
656 if (fmt_token_order[token_count] !=
'm')
659 token_values[token_count] = -1;
661 free(month_lower_tmp);
665 for (
i = 0;
i < 3;
i++)
667 *(str_copy +
token[
i][1] + 1) =
'\0';
669 if (token_values[
i] == -1)
672 token_values[
i] = strtol(str_copy +
token[
i][0], (
char **) NULL, 10);
675 token_values[
i] = -1;
677 if (fmt_token_order[
i] ==
'd')
679 else if (fmt_token_order[
i] ==
'm')
681 else if (fmt_token_order[
i] ==
'y')
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
void j2date(int jd, int *year, int *month, int *day)
void GetCurrentDateTime(struct pg_tm *tm)
const char *const months[]
void EncodeDateOnly(struct pg_tm *tm, int style, char *str)
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, DateTimeErrorExtra *extra)
int date2j(int year, int month, int day)
void GetEpochTime(struct pg_tm *tm)
#define TIMESTAMP_NOT_FINITE(j)
char * pgtypes_date_months[]
char * pgtypes_date_weekdays_short[]
char * pgtypes_strdup(const char *str)
char * pgtypes_alloc(long size)
#define PGTYPES_DATE_MONTH_MAXLENGTH
date PGTYPESdate_from_timestamp(timestamp dt)
int PGTYPESdate_dayofweek(date dDate)
void PGTYPESdate_today(date *d)
#define PGTYPES_FMTDATE_DAY_DIGITS_LZ
date PGTYPESdate_from_asc(char *str, char **endptr)
int PGTYPESdate_fmt_asc(date dDate, const char *fmtstring, char *outbuf)
#define PGTYPES_FMTDATE_MONTH_DIGITS_LZ
int PGTYPESdate_defmt_asc(date *d, const char *fmt, const char *str)
void PGTYPESdate_julmdy(date jd, int *mdy)
void PGTYPESdate_free(date *d)
void PGTYPESdate_mdyjul(int *mdy, date *jdate)
#define PGTYPES_FMTDATE_DOW_LITERAL_SHORT
#define PGTYPES_FMTDATE_YEAR_DIGITS_LONG
#define PGTYPES_FMTDATE_YEAR_DIGITS_SHORT
#define PGTYPES_DATE_NUM_MAX_DIGITS
char * PGTYPESdate_to_asc(date dDate)
#define PGTYPES_FMTDATE_MONTH_LITERAL_SHORT
date * PGTYPESdate_new(void)
static void const char * fmt
#define PGTYPES_DATE_ERR_ENOTDMY
#define PGTYPES_DATE_BAD_DAY
#define PGTYPES_DATE_BAD_DATE
#define PGTYPES_DATE_ERR_ENOSHORTDATE
#define PGTYPES_DATE_ERR_EARGS
#define PGTYPES_DATE_BAD_MONTH
#define PGTYPES_TYPE_STRING_CONSTANT
#define PGTYPES_TYPE_UINT
#define PGTYPES_TYPE_STRING_MALLOCED
#define PGTYPES_TYPE_UINT_4_LZ
#define PGTYPES_TYPE_UINT_2_LZ
unsigned char pg_tolower(unsigned char ch)