summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2009-05-26 02:17:50 +0000
committerTom Lane2009-05-26 02:17:50 +0000
commit83a3d0689a70c70c6488f3310ed2c36fc9b59f0e (patch)
tree277d8cdc263c9974c72992ef325b2631c86833d3
parent0fd3aa808d7003c7ad0f4205101546a57298e853 (diff)
Remove the useless and rather inconsistent return values of EncodeDateOnly,
EncodeTimeOnly, EncodeDateTime, EncodeInterval. These don't have any good reason to fail, and their callers were mostly not checking anyway.
-rw-r--r--src/backend/utils/adt/datetime.c32
-rw-r--r--src/backend/utils/adt/timestamp.c3
-rw-r--r--src/include/utils/datetime.h8
3 files changed, 13 insertions, 30 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 6020a9e3cb..abbe0f804a 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -3601,11 +3601,10 @@ EncodeTimezone(char *str, int tz, int style)
/* EncodeDateOnly()
* Encode date as local time.
*/
-int
+void
EncodeDateOnly(struct pg_tm * tm, int style, char *str)
{
- if (tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR)
- return -1;
+ Assert(tm->tm_mon >= 1 && tm->tm_mon <= MONTHS_PER_YEAR);
switch (style)
{
@@ -3654,20 +3653,15 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
sprintf(str + 5, "-%04d %s", -(tm->tm_year - 1), "BC");
break;
}
-
- return TRUE;
-} /* EncodeDateOnly() */
+}
/* EncodeTimeOnly()
* Encode time fields only.
*/
-int
+void
EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
{
- if (tm->tm_hour < 0 || tm->tm_hour > HOURS_PER_DAY)
- return -1;
-
sprintf(str, "%02d:%02d:", tm->tm_hour, tm->tm_min);
str += strlen(str);
@@ -3675,9 +3669,7 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
if (tzp != NULL)
EncodeTimezone(str, *tzp, style);
-
- return TRUE;
-} /* EncodeTimeOnly() */
+}
/* EncodeDateTime()
@@ -3692,15 +3684,11 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
* US - mm/dd/yyyy
* European - dd/mm/yyyy
*/
-int
+void
EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str)
{
int day;
- /*
- * Why are we checking only the month field? Change this to an assert...
- * if (tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR) return -1;
- */
Assert(tm->tm_mon >= 1 && tm->tm_mon <= MONTHS_PER_YEAR);
switch (style)
@@ -3825,8 +3813,6 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
sprintf(str + strlen(str), " BC");
break;
}
-
- return TRUE;
}
@@ -3906,7 +3892,7 @@ AddVerboseIntPart(char *cp, int value, const char *units,
* "year-month literal"s (that look like '2-3') and
* "day-time literal"s (that look like ('4 5:6:7')
*/
-int
+void
EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
{
char *cp = str;
@@ -4083,9 +4069,7 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
strcat(cp, " ago");
break;
}
-
- return 0;
-} /* EncodeInterval() */
+}
/*
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 6956497968..38b36385e9 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -684,8 +684,7 @@ interval_out(PG_FUNCTION_ARGS)
if (interval2tm(*span, tm, &fsec) != 0)
elog(ERROR, "could not convert interval to tm");
- if (EncodeInterval(tm, fsec, IntervalStyle, buf) != 0)
- elog(ERROR, "could not format interval");
+ EncodeInterval(tm, fsec, IntervalStyle, buf);
result = pstrdup(buf);
PG_RETURN_CSTRING(result);
diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h
index 3403f0fa73..9a2690500f 100644
--- a/src/include/utils/datetime.h
+++ b/src/include/utils/datetime.h
@@ -299,10 +299,10 @@ extern void DateTimeParseError(int dterr, const char *str,
extern int DetermineTimeZoneOffset(struct pg_tm * tm, pg_tz *tzp);
-extern int EncodeDateOnly(struct pg_tm * tm, int style, char *str);
-extern int EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str);
-extern int EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str);
-extern int EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str);
+extern void EncodeDateOnly(struct pg_tm * tm, int style, char *str);
+extern void EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str);
+extern void EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str);
+extern void EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str);
extern int DecodeSpecial(int field, char *lowtoken, int *val);
extern int DecodeUnits(int field, char *lowtoken, int *val);