Skip to content

Commit 84ce258

Browse files
committed
Replace float8 with int in date2isoweek() and date2isoyear().
The values of the "result" variables in these functions are always integers; using a float8 variable accomplishes nothing except to incur useless conversions to and from float. While that wastes a few nanoseconds, these functions aren't all that time-critical. But it seems worth fixing to remove possible reader confusion. Also, in the case of date2isoyear(), "result" is a very poorly chosen variable name because it is *not* the function's result. Rename it to "week", and do the same in date2isoweek() for consistency. Since this is mostly cosmetic, there seems little need for back-patch. Author: Sergey Fukanchik <s.fukanchik@postgrespro.ru> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/6323a-68726500-1-7def9d00@137821581
1 parent f2c87ac commit 84ce258

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5312,10 +5312,10 @@ isoweekdate2date(int isoweek, int wday, int *year, int *mon, int *mday)
53125312
int
53135313
date2isoweek(int year, int mon, int mday)
53145314
{
5315-
float8 result;
53165315
int day0,
53175316
day4,
5318-
dayn;
5317+
dayn,
5318+
week;
53195319

53205320
/* current day */
53215321
dayn = date2j(year, mon, mday);
@@ -5338,24 +5338,24 @@ date2isoweek(int year, int mon, int mday)
53385338
day0 = j2day(day4 - 1);
53395339
}
53405340

5341-
result = (dayn - (day4 - day0)) / 7 + 1;
5341+
week = (dayn - (day4 - day0)) / 7 + 1;
53425342

53435343
/*
53445344
* Sometimes the last few days in a year will fall into the first week of
53455345
* the next year, so check for this.
53465346
*/
5347-
if (result >= 52)
5347+
if (week >= 52)
53485348
{
53495349
day4 = date2j(year + 1, 1, 4);
53505350

53515351
/* day0 == offset to first day of week (Monday) */
53525352
day0 = j2day(day4 - 1);
53535353

53545354
if (dayn >= day4 - day0)
5355-
result = (dayn - (day4 - day0)) / 7 + 1;
5355+
week = (dayn - (day4 - day0)) / 7 + 1;
53565356
}
53575357

5358-
return (int) result;
5358+
return week;
53595359
}
53605360

53615361

@@ -5367,10 +5367,10 @@ date2isoweek(int year, int mon, int mday)
53675367
int
53685368
date2isoyear(int year, int mon, int mday)
53695369
{
5370-
float8 result;
53715370
int day0,
53725371
day4,
5373-
dayn;
5372+
dayn,
5373+
week;
53745374

53755375
/* current day */
53765376
dayn = date2j(year, mon, mday);
@@ -5395,13 +5395,13 @@ date2isoyear(int year, int mon, int mday)
53955395
year--;
53965396
}
53975397

5398-
result = (dayn - (day4 - day0)) / 7 + 1;
5398+
week = (dayn - (day4 - day0)) / 7 + 1;
53995399

54005400
/*
54015401
* Sometimes the last few days in a year will fall into the first week of
54025402
* the next year, so check for this.
54035403
*/
5404-
if (result >= 52)
5404+
if (week >= 52)
54055405
{
54065406
day4 = date2j(year + 1, 1, 4);
54075407

0 commit comments

Comments
 (0)