mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-02 07:21:22 +02:00
Add 'GERMAN' style to date/time output.
Probably have it wrong (dd.mm/yyyy) but can change it when we know. Input routines always handled it.
This commit is contained in:
parent
d7e0e61d84
commit
352b36877f
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.44 1997/11/17 16:23:33 thomas Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.45 1997/12/04 23:30:52 thomas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -4099,103 +4099,54 @@ EncodeSpecialDateTime(DateTime dt, char *str)
|
|||||||
int
|
int
|
||||||
EncodeDateOnly(struct tm * tm, int style, char *str)
|
EncodeDateOnly(struct tm * tm, int style, char *str)
|
||||||
{
|
{
|
||||||
#if FALSE
|
|
||||||
int day;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((tm->tm_mon < 1) || (tm->tm_mon > 12))
|
if ((tm->tm_mon < 1) || (tm->tm_mon > 12))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
switch (style)
|
||||||
|
{
|
||||||
/* compatible with ISO date formats */
|
/* compatible with ISO date formats */
|
||||||
if (style == USE_ISO_DATES)
|
case USE_ISO_DATES:
|
||||||
{
|
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
{
|
|
||||||
sprintf(str, "%04d-%02d-%02d",
|
sprintf(str, "%04d-%02d-%02d",
|
||||||
tm->tm_year, tm->tm_mon, tm->tm_mday);
|
tm->tm_year, tm->tm_mon, tm->tm_mday);
|
||||||
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf(str, "%04d-%02d-%02d %s",
|
sprintf(str, "%04d-%02d-%02d %s",
|
||||||
-(tm->tm_year - 1), tm->tm_mon, tm->tm_mday, "BC");
|
-(tm->tm_year - 1), tm->tm_mon, tm->tm_mday, "BC");
|
||||||
}
|
break;
|
||||||
|
|
||||||
/* compatible with Oracle/Ingres date formats */
|
/* compatible with Oracle/Ingres date formats */
|
||||||
}
|
case USE_SQL_DATES:
|
||||||
else if (style == USE_SQL_DATES)
|
|
||||||
{
|
|
||||||
if (EuroDates)
|
if (EuroDates)
|
||||||
{
|
|
||||||
sprintf(str, "%02d/%02d", tm->tm_mday, tm->tm_mon);
|
sprintf(str, "%02d/%02d", tm->tm_mday, tm->tm_mon);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
|
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
|
||||||
}
|
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
{
|
|
||||||
sprintf((str + 5), "/%04d", tm->tm_year);
|
sprintf((str + 5), "/%04d", tm->tm_year);
|
||||||
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf((str + 5), "/%04d %s", -(tm->tm_year - 1), "BC");
|
sprintf((str + 5), "/%04d %s", -(tm->tm_year - 1), "BC");
|
||||||
}
|
break;
|
||||||
|
|
||||||
/* backward-compatible with traditional Postgres abstime dates */
|
/* German-style date format */
|
||||||
}
|
case USE_GERMAN_DATES:
|
||||||
else
|
sprintf(str, "%02d.%02d", tm->tm_mday, tm->tm_mon);
|
||||||
{ /* if (style == USE_POSTGRES_DATES) */
|
|
||||||
|
|
||||||
#if FALSE
|
|
||||||
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
|
||||||
#ifdef DATEDEBUG
|
|
||||||
printf("EncodeDateOnly- day is %d\n", day);
|
|
||||||
#endif
|
|
||||||
tm->tm_wday = j2day(day);
|
|
||||||
|
|
||||||
strncpy(str, days[tm->tm_wday], 3);
|
|
||||||
strcpy((str + 3), " ");
|
|
||||||
|
|
||||||
if (EuroDates)
|
|
||||||
{
|
|
||||||
sprintf((str + 4), "%02d %3s", tm->tm_mday, months[tm->tm_mon - 1]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf((str + 4), "%3s %02d", months[tm->tm_mon - 1], tm->tm_mday);
|
|
||||||
}
|
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
{
|
sprintf((str + 5), "/%04d", tm->tm_year);
|
||||||
sprintf((str + 10), " %04d", tm->tm_year);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
sprintf((str + 5), "/%04d %s", -(tm->tm_year - 1), "BC");
|
||||||
sprintf((str + 10), " %04d %s", -(tm->tm_year - 1), "BC");
|
break;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* traditional date-only style for Postgres */
|
/* traditional date-only style for Postgres */
|
||||||
|
case USE_POSTGRES_DATES:
|
||||||
|
default:
|
||||||
if (EuroDates)
|
if (EuroDates)
|
||||||
{
|
|
||||||
sprintf(str, "%02d-%02d", tm->tm_mday, tm->tm_mon);
|
sprintf(str, "%02d-%02d", tm->tm_mday, tm->tm_mon);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf(str, "%02d-%02d", tm->tm_mon, tm->tm_mday);
|
sprintf(str, "%02d-%02d", tm->tm_mon, tm->tm_mday);
|
||||||
}
|
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
{
|
|
||||||
sprintf((str + 5), "-%04d", tm->tm_year);
|
sprintf((str + 5), "-%04d", tm->tm_year);
|
||||||
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf((str + 5), "-%04d %s", -(tm->tm_year - 1), "BC");
|
sprintf((str + 5), "-%04d %s", -(tm->tm_year - 1), "BC");
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DATEDEBUG
|
#ifdef DATEDEBUG
|
||||||
@ -4232,6 +4183,14 @@ EncodeTimeOnly(struct tm * tm, double fsec, int style, char *str)
|
|||||||
|
|
||||||
/* EncodeDateTime()
|
/* EncodeDateTime()
|
||||||
* Encode date and time interpreted as local time.
|
* Encode date and time interpreted as local time.
|
||||||
|
* Support several date styles:
|
||||||
|
* Postgres - day mon hh:mm:ss yyyy tz
|
||||||
|
* SQL - mm/dd/yyyy hh:mm:ss.ss tz
|
||||||
|
* ISO - yyyy-mm-dd hh:mm:ss+/-tz
|
||||||
|
* German - dd.mm/yyyy hh:mm:ss tz
|
||||||
|
* Variants (affects order of month and day for Postgres and SQL styles):
|
||||||
|
* US - mm/dd/yyyy
|
||||||
|
* European - dd/mm/yyyy
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, char *str)
|
EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, char *str)
|
||||||
@ -4261,9 +4220,11 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* compatible with ISO date formats */
|
switch (style)
|
||||||
if (style == USE_ISO_DATES)
|
|
||||||
{
|
{
|
||||||
|
/* compatible with ISO date formats */
|
||||||
|
|
||||||
|
case USE_ISO_DATES:
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
{
|
{
|
||||||
sprintf(str, "%04d-%02d-%02d %02d:%02d:",
|
sprintf(str, "%04d-%02d-%02d %02d:%02d:",
|
||||||
@ -4289,29 +4250,21 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (tm->tm_hour || tm->tm_min)
|
if (tm->tm_hour || tm->tm_min)
|
||||||
{
|
|
||||||
sprintf(str, "%04d-%02d-%02d %02d:%02d %s",
|
sprintf(str, "%04d-%02d-%02d %02d:%02d %s",
|
||||||
-(tm->tm_year - 1), tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, "BC");
|
-(tm->tm_year - 1), tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, "BC");
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf(str, "%04d-%02d-%02d %s",
|
sprintf(str, "%04d-%02d-%02d %s",
|
||||||
-(tm->tm_year - 1), tm->tm_mon, tm->tm_mday, "BC");
|
-(tm->tm_year - 1), tm->tm_mon, tm->tm_mday, "BC");
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
|
|
||||||
/* compatible with Oracle/Ingres date formats */
|
/* compatible with Oracle/Ingres date formats */
|
||||||
}
|
case USE_SQL_DATES:
|
||||||
else if (style == USE_SQL_DATES)
|
|
||||||
{
|
|
||||||
if (EuroDates)
|
if (EuroDates)
|
||||||
{
|
|
||||||
sprintf(str, "%02d/%02d", tm->tm_mday, tm->tm_mon);
|
sprintf(str, "%02d/%02d", tm->tm_mday, tm->tm_mon);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
|
sprintf(str, "%02d/%02d", tm->tm_mon, tm->tm_mday);
|
||||||
}
|
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
{
|
{
|
||||||
sprintf((str + 5), "/%04d %02d:%02d:%05.2f",
|
sprintf((str + 5), "/%04d %02d:%02d:%05.2f",
|
||||||
@ -4325,15 +4278,33 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
|
|||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf((str + 5), "/%04d %02d:%02d %s",
|
sprintf((str + 5), "/%04d %02d:%02d %s",
|
||||||
-(tm->tm_year - 1), tm->tm_hour, tm->tm_min, "BC");
|
-(tm->tm_year - 1), tm->tm_hour, tm->tm_min, "BC");
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* German variant on European style; note mixed delimiters dd.mm/yyyy */
|
||||||
|
case USE_GERMAN_DATES:
|
||||||
|
sprintf(str, "%02d.%02d", tm->tm_mday, tm->tm_mon);
|
||||||
|
if (tm->tm_year > 0)
|
||||||
|
{
|
||||||
|
sprintf((str + 5), "/%04d %02d:%02d:%05.2f",
|
||||||
|
tm->tm_year, tm->tm_hour, tm->tm_min, sec);
|
||||||
|
|
||||||
|
if ((*tzn != NULL) && (tm->tm_isdst >= 0))
|
||||||
|
{
|
||||||
|
strcpy((str + 22), " ");
|
||||||
|
strcpy((str + 23), *tzn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* backward-compatible with traditional Postgres abstime dates */
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /* if (style == USE_POSTGRES_DATES) */
|
sprintf((str + 5), "/%04d %02d:%02d %s",
|
||||||
|
-(tm->tm_year - 1), tm->tm_hour, tm->tm_min, "BC");
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* backward-compatible with traditional Postgres abstime dates */
|
||||||
|
case USE_POSTGRES_DATES:
|
||||||
|
default:
|
||||||
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
||||||
#ifdef DATEDEBUG
|
#ifdef DATEDEBUG
|
||||||
printf("EncodeDateTime- day is %d\n", day);
|
printf("EncodeDateTime- day is %d\n", day);
|
||||||
@ -4344,13 +4315,10 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
|
|||||||
strcpy((str + 3), " ");
|
strcpy((str + 3), " ");
|
||||||
|
|
||||||
if (EuroDates)
|
if (EuroDates)
|
||||||
{
|
|
||||||
sprintf((str + 4), "%02d %3s", tm->tm_mday, months[tm->tm_mon - 1]);
|
sprintf((str + 4), "%02d %3s", tm->tm_mday, months[tm->tm_mon - 1]);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sprintf((str + 4), "%3s %02d", months[tm->tm_mon - 1], tm->tm_mday);
|
sprintf((str + 4), "%3s %02d", months[tm->tm_mon - 1], tm->tm_mday);
|
||||||
}
|
|
||||||
if (tm->tm_year > 0)
|
if (tm->tm_year > 0)
|
||||||
{
|
{
|
||||||
sprintf((str + 10), " %02d:%02d", tm->tm_hour, tm->tm_min);
|
sprintf((str + 10), " %02d:%02d", tm->tm_hour, tm->tm_min);
|
||||||
@ -4379,6 +4347,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
|
|||||||
sprintf((str + 10), " %02d:%02d %04d %s",
|
sprintf((str + 10), " %02d:%02d %04d %s",
|
||||||
tm->tm_hour, tm->tm_min, -(tm->tm_year - 1), "BC");
|
tm->tm_hour, tm->tm_min, -(tm->tm_year - 1), "BC");
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DATEDEBUG
|
#ifdef DATEDEBUG
|
||||||
|
Loading…
Reference in New Issue
Block a user