Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3ce0236

Browse files
committed
Apply date patch from tiemann@cygnus.com,Michael Tiemann.
1 parent162c2a6 commit3ce0236

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

‎src/backend/utils/adt/datetimes.c

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.8 1997/01/26 15:31:12 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.9 1997/03/02 02:05:33 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -240,32 +240,54 @@ date_smaller(int4 dateVal1, int4 dateVal2)
240240
int32
241241
date_mi(int4dateVal1,int4dateVal2)
242242
{
243+
int4dv1,dv2;
243244
DateADT*date1,*date2;
244245
int32days=0;
245246
inti;
246247

247-
date1= (DateADT*)&dateVal1;
248-
date2= (DateADT*)&dateVal2;
248+
/* This circumlocution allows us to assume that date1 is always
249+
before date2. */
250+
dv1=date_smaller (dateVal1,dateVal2);
251+
dv2=date_larger (dateVal1,dateVal2);
252+
date1= (DateADT*)&dv1;
253+
date2= (DateADT*)&dv2;
249254

250255
/* Sum number of days in each full year between date1 and date2. */
251256
for (i=date1->year+1;i<date2->year;++i)
252257
days+=isleap (i) ?366 :365;
253258

254-
/* Add in number of days in each full month from date1 to end of
255-
year. */
256-
for (i=date1->month+1;i <=12;++i)
257-
days+=day_tab[isleap (date1->year)][i-1];
258-
259-
/* Add in number of days in each full month from start of year to
260-
date2. */
261-
for (i=1;i<date2->month;++i)
262-
days+=day_tab[isleap (date2->year)][i-1];
259+
if (days)
260+
{
261+
/* We need to wrap around the year. Add in number of days in each
262+
full month from date1 to end of year. */
263+
for (i=date1->month+1;i <=12;++i)
264+
days+=day_tab[isleap (date1->year)][i-1];
265+
266+
/* Add in number of days in each full month from start of year to
267+
date2. */
268+
for (i=1;i<date2->month;++i)
269+
days+=day_tab[isleap (date2->year)][i-1];
270+
}
271+
else
272+
{
273+
/* Add in number of days in each full month from date1 to date2. */
274+
for (i=date1->month+1;i<date2->month;++i)
275+
days+=day_tab[isleap (date1->year)][i-1];
276+
}
263277

264-
/* Add in number of days left in month for date1. */
265-
days+=day_tab[isleap (date1->year)][date1->month-1]-date1->day;
278+
if (days||date1->month!=date2->month)
279+
{
280+
/* Add in number of days left in month for date1. */
281+
days+=day_tab[isleap (date1->year)][date1->month-1]-date1->day;
266282

267-
/* Add in day of month of date2. */
268-
days+=date2->day;
283+
/* Add in day of month of date2. */
284+
days+=date2->day;
285+
}
286+
else
287+
{
288+
/* Everything's in the same month, so just subtract the days! */
289+
days=date2->day-date1->day;
290+
}
269291

270292
return (days);
271293
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp