Skip to content

Commit a412749

Browse files
committed
Replace overly-cute coding with code that (a) has defined behavior
according to the ANSI C spec, (b) gets the boundary conditions right, and (c) is about a third as long and three times more intelligible.
1 parent 90f4284 commit a412749

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/backend/utils/adt/formatting.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.27 2000/12/15 19:15:09 momjian Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.28 2000/12/23 04:05:31 tgl Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
@@ -2775,16 +2775,14 @@ to_timestamp(PG_FUNCTION_ARGS)
27752775
#endif
27762776
if (tmfc->ssss)
27772777
{
2778-
int x;
2779-
2780-
if (tmfc->ssss > 3600)
2781-
tm->tm_sec = x - ((tm->tm_min = (x = tmfc->ssss -
2782-
((tm->tm_hour= tmfc->ssss / 3600) * 3600)) / 60) * 60);
2783-
else if (tmfc->ssss > 60)
2784-
tm->tm_sec = tmfc->ssss - ((tm->tm_min = tmfc->ssss / 60) * 60);
2785-
else
2786-
tm->tm_sec = tmfc->ssss;
2787-
}
2778+
int x = tmfc->ssss;
2779+
2780+
tm->tm_hour = x / 3600;
2781+
x %= 3600;
2782+
tm->tm_min = x / 60;
2783+
x %= 60;
2784+
tm->tm_sec = x;
2785+
}
27882786

27892787
if (tmfc->cc)
27902788
tm->tm_year = (tmfc->cc-1) * 100;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy