1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-10-31 14:14:28 +03:00

Fixes to the handling of time 24:00:00.

[forum:/info/2026-10-15T10:26:06Z|Forum post 2026-10-15T10:26:06Z]

FossilOrigin-Name: 69071e25cad52b7fe15749f5fb969e847f9cd65e66341e8d1d4e5f5282283cd4
This commit is contained in:
drh
2026-10-15 13:19:18 +00:00
parent 23500fbf19
commit 1bf6883244
4 changed files with 47 additions and 27 deletions

View File

@@ -302,6 +302,21 @@ static void computeJD(DateTime *p){
}
}
/*
** Return the number of dates in a specific month.
*/
static int daysOfMonth(int Y, int M){
if( (1<<M) & 0x15aa ){
return 31;
}else if( M!=2 ){
return 30;
}else if( Y%4==0 && (Y%100!=0 || Y%400==0) ){
return 29;
}else{
return 28;
}
}
/*
** Given the YYYY-MM-DD information current in p, determine if there
** is day-of-month overflow and set nFloor to the number of days that
@@ -309,24 +324,12 @@ static void computeJD(DateTime *p){
** date back to the end of the month.
*/
static void computeFloor(DateTime *p){
int mxD; /* Maximum day number for the current month */
assert( p->validYMD || p->isError );
assert( p->D>=0 && p->D<=31 );
assert( p->D>=0 && p->D<=32 );
assert( p->M>=0 && p->M<=12 );
if( p->validHMS && p->h==24 ){
p->h = 0;
p->D++;
}
if( p->D<=28 ){
p->nFloor = 0;
}else if( (1<<p->M) & 0x15aa ){
p->nFloor = 0;
}else if( p->M!=2 ){
p->nFloor = (p->D==31);
}else if( p->Y%4!=0 || (p->Y%100==0 && p->Y%400!=0) ){
p->nFloor = p->D - 28;
}else{
p->nFloor = p->D - 29;
}
mxD = daysOfMonth(p->Y, p->M);
p->nFloor = p->D>mxD ? p->D - mxD : 0;
}
/*
@@ -356,7 +359,19 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
zDate += 10;
while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; }
if( parseHhMmSs(zDate, p)==0 ){
/* We got the time */
if( p->h==24 ){
int mxD = daysOfMonth(Y,M);
p->h = 0;
D++;
if( D>mxD ){
D -= mxD;
M++;
if( M>12 ){
M = 1;
Y++;
}
}
}
}else if( *zDate==0 ){
p->validHMS = 0;
}else{