mirror of
https://github.com/postgres/postgres.git
synced 2025-10-21 02:52:47 +03:00
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
This commit is contained in:
@@ -5312,10 +5312,10 @@ isoweekdate2date(int isoweek, int wday, int *year, int *mon, int *mday)
|
||||
int
|
||||
date2isoweek(int year, int mon, int mday)
|
||||
{
|
||||
float8 result;
|
||||
int day0,
|
||||
day4,
|
||||
dayn;
|
||||
dayn,
|
||||
week;
|
||||
|
||||
/* current day */
|
||||
dayn = date2j(year, mon, mday);
|
||||
@@ -5338,13 +5338,13 @@ date2isoweek(int year, int mon, int mday)
|
||||
day0 = j2day(day4 - 1);
|
||||
}
|
||||
|
||||
result = (dayn - (day4 - day0)) / 7 + 1;
|
||||
week = (dayn - (day4 - day0)) / 7 + 1;
|
||||
|
||||
/*
|
||||
* Sometimes the last few days in a year will fall into the first week of
|
||||
* the next year, so check for this.
|
||||
*/
|
||||
if (result >= 52)
|
||||
if (week >= 52)
|
||||
{
|
||||
day4 = date2j(year + 1, 1, 4);
|
||||
|
||||
@@ -5352,10 +5352,10 @@ date2isoweek(int year, int mon, int mday)
|
||||
day0 = j2day(day4 - 1);
|
||||
|
||||
if (dayn >= day4 - day0)
|
||||
result = (dayn - (day4 - day0)) / 7 + 1;
|
||||
week = (dayn - (day4 - day0)) / 7 + 1;
|
||||
}
|
||||
|
||||
return (int) result;
|
||||
return week;
|
||||
}
|
||||
|
||||
|
||||
@@ -5367,10 +5367,10 @@ date2isoweek(int year, int mon, int mday)
|
||||
int
|
||||
date2isoyear(int year, int mon, int mday)
|
||||
{
|
||||
float8 result;
|
||||
int day0,
|
||||
day4,
|
||||
dayn;
|
||||
dayn,
|
||||
week;
|
||||
|
||||
/* current day */
|
||||
dayn = date2j(year, mon, mday);
|
||||
@@ -5395,13 +5395,13 @@ date2isoyear(int year, int mon, int mday)
|
||||
year--;
|
||||
}
|
||||
|
||||
result = (dayn - (day4 - day0)) / 7 + 1;
|
||||
week = (dayn - (day4 - day0)) / 7 + 1;
|
||||
|
||||
/*
|
||||
* Sometimes the last few days in a year will fall into the first week of
|
||||
* the next year, so check for this.
|
||||
*/
|
||||
if (result >= 52)
|
||||
if (week >= 52)
|
||||
{
|
||||
day4 = date2j(year + 1, 1, 4);
|
||||
|
||||
|
Reference in New Issue
Block a user