diff options
author | drh <drh@noemail.net> | 2015-12-23 10:54:48 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-12-23 10:54:48 +0000 |
commit | caeca516a7df7ca63e662006f34a1b968a20b369 (patch) | |
tree | f71a46b2af9137c4714dbe6da852cc56593358ae /src | |
parent | 1c75c9d7f16f5852c012f5fc8fce00840f72b308 (diff) | |
download | sqlite-caeca516a7df7ca63e662006f34a1b968a20b369.tar.gz sqlite-caeca516a7df7ca63e662006f34a1b968a20b369.zip |
Enhance the 'utc' modifier on date/time functions so that if the LHS is
already known to be in UTC, the modifier becomes a no-op. This is not an
incompatibility because the behavior is documented as "undefined" in that
scenario.
FossilOrigin-Name: b910a3d53769689d9212a06f974ccce54844bbe4
Diffstat (limited to 'src')
-rw-r--r-- | src/date.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/date.c b/src/date.c index 8a66eae90..3d7604ab4 100644 --- a/src/date.c +++ b/src/date.c @@ -65,6 +65,7 @@ struct DateTime { char validHMS; /* True (1) if h,m,s are valid */ char validJD; /* True (1) if iJD is valid */ char validTZ; /* True (1) if tz is valid */ + char tzSet; /* Timezone was set explicitly */ }; @@ -158,6 +159,7 @@ static int parseTimezone(const char *zDate, DateTime *p){ p->tz = sgn*(nMn + nHr*60); zulu_time: while( sqlite3Isspace(*zDate) ){ zDate++; } + p->tzSet = 1; return *zDate!=0; } @@ -590,13 +592,18 @@ static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){ } #ifndef SQLITE_OMIT_LOCALTIME else if( strcmp(z, "utc")==0 ){ - sqlite3_int64 c1; - computeJD(p); - c1 = localtimeOffset(p, pCtx, &rc); - if( rc==SQLITE_OK ){ - p->iJD -= c1; - clearYMD_HMS_TZ(p); - p->iJD += c1 - localtimeOffset(p, pCtx, &rc); + if( p->tzSet==0 ){ + sqlite3_int64 c1; + computeJD(p); + c1 = localtimeOffset(p, pCtx, &rc); + if( rc==SQLITE_OK ){ + p->iJD -= c1; + clearYMD_HMS_TZ(p); + p->iJD += c1 - localtimeOffset(p, pCtx, &rc); + } + p->tzSet = 1; + }else{ + rc = SQLITE_OK; } } #endif |