Skip to content

Commit 99bf328

Browse files
committed
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.
1 parent 8af641a commit 99bf328

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

src/backend/utils/adt/datetime.c

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.204 2009/05/01 19:29:07 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.205 2009/05/26 02:17:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3601,11 +3601,10 @@ EncodeTimezone(char *str, int tz, int style)
36013601
/* EncodeDateOnly()
36023602
* Encode date as local time.
36033603
*/
3604-
int
3604+
void
36053605
EncodeDateOnly(struct pg_tm * tm, int style, char *str)
36063606
{
3607-
if (tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR)
3608-
return -1;
3607+
Assert(tm->tm_mon >= 1 && tm->tm_mon <= MONTHS_PER_YEAR);
36093608

36103609
switch (style)
36113610
{
@@ -3654,30 +3653,23 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
36543653
sprintf(str + 5, "-%04d %s", -(tm->tm_year - 1), "BC");
36553654
break;
36563655
}
3657-
3658-
return TRUE;
3659-
} /* EncodeDateOnly() */
3656+
}
36603657

36613658

36623659
/* EncodeTimeOnly()
36633660
* Encode time fields only.
36643661
*/
3665-
int
3662+
void
36663663
EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
36673664
{
3668-
if (tm->tm_hour < 0 || tm->tm_hour > HOURS_PER_DAY)
3669-
return -1;
3670-
36713665
sprintf(str, "%02d:%02d:", tm->tm_hour, tm->tm_min);
36723666
str += strlen(str);
36733667

36743668
AppendSeconds(str, tm->tm_sec, fsec, MAX_TIME_PRECISION, true);
36753669

36763670
if (tzp != NULL)
36773671
EncodeTimezone(str, *tzp, style);
3678-
3679-
return TRUE;
3680-
} /* EncodeTimeOnly() */
3672+
}
36813673

36823674

36833675
/* EncodeDateTime()
@@ -3692,15 +3684,11 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
36923684
* US - mm/dd/yyyy
36933685
* European - dd/mm/yyyy
36943686
*/
3695-
int
3687+
void
36963688
EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str)
36973689
{
36983690
int day;
36993691

3700-
/*
3701-
* Why are we checking only the month field? Change this to an assert...
3702-
* if (tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR) return -1;
3703-
*/
37043692
Assert(tm->tm_mon >= 1 && tm->tm_mon <= MONTHS_PER_YEAR);
37053693

37063694
switch (style)
@@ -3825,8 +3813,6 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
38253813
sprintf(str + strlen(str), " BC");
38263814
break;
38273815
}
3828-
3829-
return TRUE;
38303816
}
38313817

38323818

@@ -3906,7 +3892,7 @@ AddVerboseIntPart(char *cp, int value, const char *units,
39063892
* "year-month literal"s (that look like '2-3') and
39073893
* "day-time literal"s (that look like ('4 5:6:7')
39083894
*/
3909-
int
3895+
void
39103896
EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
39113897
{
39123898
char *cp = str;
@@ -4083,9 +4069,7 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
40834069
strcat(cp, " ago");
40844070
break;
40854071
}
4086-
4087-
return 0;
4088-
} /* EncodeInterval() */
4072+
}
40894073

40904074

40914075
/*

src/backend/utils/adt/timestamp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.198 2009/04/04 04:53:25 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.199 2009/05/26 02:17:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -684,8 +684,7 @@ interval_out(PG_FUNCTION_ARGS)
684684
if (interval2tm(*span, tm, &fsec) != 0)
685685
elog(ERROR, "could not convert interval to tm");
686686

687-
if (EncodeInterval(tm, fsec, IntervalStyle, buf) != 0)
688-
elog(ERROR, "could not format interval");
687+
EncodeInterval(tm, fsec, IntervalStyle, buf);
689688

690689
result = pstrdup(buf);
691690
PG_RETURN_CSTRING(result);

src/include/utils/datetime.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $PostgreSQL: pgsql/src/include/utils/datetime.h,v 1.72 2009/01/01 17:24:02 momjian Exp $
12+
* $PostgreSQL: pgsql/src/include/utils/datetime.h,v 1.73 2009/05/26 02:17:50 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -299,10 +299,10 @@ extern void DateTimeParseError(int dterr, const char *str,
299299

300300
extern int DetermineTimeZoneOffset(struct pg_tm * tm, pg_tz *tzp);
301301

302-
extern int EncodeDateOnly(struct pg_tm * tm, int style, char *str);
303-
extern int EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str);
304-
extern int EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str);
305-
extern int EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str);
302+
extern void EncodeDateOnly(struct pg_tm * tm, int style, char *str);
303+
extern void EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str);
304+
extern void EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, char *str);
305+
extern void EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str);
306306

307307
extern int DecodeSpecial(int field, char *lowtoken, int *val);
308308
extern int DecodeUnits(int field, char *lowtoken, int *val);

0 commit comments

Comments
 (0)