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

Commit5db5146

Browse files
committed
Fix j2day() to behave sanely for negative Julian dates.
Somebody had apparently once figured that casting to unsigned int wouldproduce the right output for negative inputs, but that would only betrue if 2^32 were a multiple of 7, which of course it ain't. We needto use a signed division and then correct the sign of the remainder.AFAICT, the only case where this would arise currently is when doingISO-week calculations for dates in 4714BC, where we'd compute anegative Julian date representing 4714-01-04BC and then do somearithmetic with it. Since we don't even really document support forsuch dates, this is not of much consequence. But we may as wellget it right.Per report from Vitaly Burovoy.
1 parenta70e13a commit5db5146

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,13 @@ j2date(int jd, int *year, int *month, int *day)
355355
int
356356
j2day(intdate)
357357
{
358-
unsignedintday;
358+
date+=1;
359+
date %=7;
360+
/* Cope if division truncates towards zero, as it probably does */
361+
if (date<0)
362+
date+=7;
359363

360-
day=date;
361-
362-
day+=1;
363-
day %=7;
364-
365-
return (int)day;
364+
returndate;
366365
}/* j2day() */
367366

368367

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp