diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
| commit | 2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch) | |
| tree | 41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /ext/pdo_sqlite/sqlite/src/date.c | |
| parent | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff) | |
| download | php-upstream/5.2.2.tar.gz | |
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'ext/pdo_sqlite/sqlite/src/date.c')
| -rw-r--r-- | ext/pdo_sqlite/sqlite/src/date.c | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/ext/pdo_sqlite/sqlite/src/date.c b/ext/pdo_sqlite/sqlite/src/date.c index 914690618..a5446e128 100644 --- a/ext/pdo_sqlite/sqlite/src/date.c +++ b/ext/pdo_sqlite/sqlite/src/date.c @@ -53,6 +53,9 @@ #include <stdlib.h> #include <assert.h> #include <time.h> +#ifndef PHP_WIN32 +#include "main/php_reentrancy.h" +#endif #ifndef SQLITE_OMIT_DATETIME_FUNCS @@ -234,11 +237,11 @@ static void computeJD(DateTime *p){ X2 = 30.6001*(M+1); p->rJD = X1 + X2 + D + B - 1524.5; p->validJD = 1; - p->validYMD = 0; if( p->validHMS ){ p->rJD += (p->h*3600.0 + p->m*60.0 + p->s)/86400.0; if( p->validTZ ){ p->rJD -= p->tz*60/86400.0; + p->validYMD = 0; p->validHMS = 0; p->validTZ = 0; } @@ -357,6 +360,7 @@ static void computeYMD(DateTime *p){ static void computeHMS(DateTime *p){ int Z, s; if( p->validHMS ) return; + computeJD(p); Z = p->rJD + 0.5; s = (p->rJD + 0.5 - Z)*86400000.0 + 0.5; p->s = 0.001*s; @@ -393,7 +397,7 @@ static void clearYMD_HMS_TZ(DateTime *p){ static double localtimeOffset(DateTime *p){ DateTime x, y; time_t t; - struct tm *pTm; + struct tm *pTm, tmbuf; x = *p; computeYMD_HMS(&x); if( x.Y<1971 || x.Y>=2038 ){ @@ -412,7 +416,7 @@ static double localtimeOffset(DateTime *p){ computeJD(&x); t = (x.rJD-2440587.5)*86400.0 + 0.5; sqlite3OsEnterMutex(); - pTm = localtime(&t); + pTm = php_localtime_r(&t, &tmbuf); y.Y = pTm->tm_year + 1900; y.M = pTm->tm_mon + 1; y.D = pTm->tm_mday; @@ -561,7 +565,7 @@ static int parseModifier(const char *zMod, DateTime *p){ case '8': case '9': { n = getValue(z, &r); - if( n<=0 ) break; + assert( n>=1 ); if( z[n]==':' ){ /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the ** specified number of hours, minutes, seconds, and fractional seconds @@ -581,7 +585,7 @@ static int parseModifier(const char *zMod, DateTime *p){ if( z[0]=='-' ) tx.rJD = -tx.rJD; computeJD(p); clearYMD_HMS_TZ(p); - p->rJD += tx.rJD; + p->rJD += tx.rJD; rc = 0; break; } @@ -809,9 +813,9 @@ static void strftimeFunc( switch( zFmt[i] ){ case 'd': sprintf(&z[j],"%02d",x.D); j+=2; break; case 'f': { - int s = x.s; - int ms = (x.s - s)*1000.0; - sprintf(&z[j],"%02d.%03d",s,ms); + double s = x.s; + if( s>59.999 ) s = 59.999; + sqlite3_snprintf(7, &z[j],"%06.3f", s); j += strlen(&z[j]); break; } @@ -824,7 +828,7 @@ static void strftimeFunc( y.M = 1; y.D = 1; computeJD(&y); - nDay = x.rJD - y.rJD; + nDay = x.rJD - y.rJD + 0.5; if( zFmt[i]=='W' ){ int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */ wd = ((int)(x.rJD+0.5)) % 7; @@ -844,7 +848,7 @@ static void strftimeFunc( j += strlen(&z[j]); break; } - case 'S': sprintf(&z[j],"%02d",(int)(x.s+0.5)); j+=2; break; + case 'S': sprintf(&z[j],"%02d",(int)x.s); j+=2; break; case 'w': z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break; case 'Y': sprintf(&z[j],"%04d",x.Y); j+=strlen(&z[j]); break; case '%': z[j++] = '%'; break; @@ -944,9 +948,21 @@ static void currentTimeFunc( } #endif - sqlite3OsEnterMutex(); - strftime(zBuf, 20, zFormat, gmtime(&t)); - sqlite3OsLeaveMutex(); +#ifdef HAVE_GMTIME_R + { + struct tm sNow; + gmtime_r(&t, &sNow); + strftime(zBuf, 20, zFormat, &sNow); + } +#else + { + struct tm *pTm; + sqlite3OsEnterMutex(); + pTm = gmtime(&t); + strftime(zBuf, 20, zFormat, pTm); + sqlite3OsLeaveMutex(); + } +#endif sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); } |
