1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

The documentation says that the built-in date-time functions give undefined

results for dates before 0000-01-01 and after 9999-12-31.  Change the
actually implementation so that the answer given is really NULL.  This also
avoids unnecessary hand-wringing over an signed integer overflow that might
otherwise occur when processing out-of-bound dates.

FossilOrigin-Name: d410a839752153c6d8be08f758abfbc16475745a
This commit is contained in:
drh
2016-11-29 20:39:48 +00:00
parent bc60368d6f
commit 3edb157e23
4 changed files with 25 additions and 20 deletions

View File

@@ -75,6 +75,7 @@ struct DateTime {
char validJD; /* True (1) if iJD is valid */
char validTZ; /* True (1) if tz is valid */
char tzSet; /* Timezone was set explicitly */
char isError; /* An overflow has occurred */
};
@@ -366,6 +367,15 @@ static int parseDateOrTime(
return 1;
}
/*
** Return TRUE if the given julian day number is within range.
**
** The input is the JulianDay times 86400000.
*/
static int validJulianDay(sqlite3_int64 iJD){
return iJD>=148699540800000 && iJD<=464269060799999;
}
/*
** Compute the Year, Month, and Day from the julian day number.
*/
@@ -376,6 +386,10 @@ static void computeYMD(DateTime *p){
p->Y = 2000;
p->M = 1;
p->D = 1;
}else if( !validJulianDay(p->iJD) ){
memset(p, 0, sizeof(*p));
p->isError = 1;
return;
}else{
Z = (int)((p->iJD + 43200000)/86400000);
A = (int)((Z - 1867216.25)/36524.25);
@@ -814,6 +828,7 @@ static int isDate(
z = sqlite3_value_text(argv[i]);
if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
}
if( p->isError || (p->validJD && !validJulianDay(p->iJD)) ) return 1;
return 0;
}