]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
New date/time modifier: (+|-)YYYY-MM-DD HH:MM(:SS.SSS)?
authordrh <>
Mon, 29 May 2023 20:33:33 +0000 (20:33 +0000)
committerdrh <>
Mon, 29 May 2023 20:33:33 +0000 (20:33 +0000)
FossilOrigin-Name: 3832b8a9ef84d9b53b48dfce9c1e724897cd7b3e05711e01675419655f894eac

manifest
manifest.uuid
src/date.c

index 7bca2b96d283b29372cbbe3a67a0ef04d98a775e..a1547dded7a64878f6ef6c4581e7010fe9f48471 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Prototype\simplementation\sof\sa\sproposed\s"timediff(X,Y)"\sSQL\sfunction.
-D 2023-05-29T18:01:42.123
+C New\sdate/time\smodifier:\s\s(+|-)YYYY-MM-DD\sHH:MM(:SS.SSS)?
+D 2023-05-29T20:33:33.570
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -583,7 +583,7 @@ F src/build.c 5512d5a335334b48d116f1ecd051edef96a60add18ae48e0ea302a395f00f3d9
 F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490
 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
 F src/ctime.c 20507cc0b0a6c19cd882fcd0eaeda32ae6a4229fb4b024cfdf3183043d9b703d
-F src/date.c 6ac049e14f0da389ed5f5166d7beefd7c456a736f859f2d82c6a0755d1eb644e
+F src/date.c 3752bcd1a5b90147f28fff2a32877935afe10d79ac33a08f24ddf820c5d2e924
 F src/dbpage.c f3eea5f7ec47e09ee7da40f42b25092ecbe961fc59566b8e5f705f34335b2387
 F src/dbstat.c ec92074baa61d883de58c945162d9e666c13cd7cf3a23bc38b4d1c4d0b2c2bef
 F src/delete.c 05e27e3a55dcfeadf2f7ca95a5c5e0928f182c04640ec1954ffa42f3d5c19341
@@ -2071,11 +2071,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 736a79c1491065f4ee77ce644af0e529e555ca733c78dbd55487d55d4ddbe5bd
-R 7cd65956485b173b36f53ea0da1803ea
-T *branch * timediff
-T *sym-timediff *
-T -sym-trunk *
+P 054a195125a273bab026ada5f07cc7c32818007027a1fd028ca59d2f179276d4
+R b507ad1612c7c470e9ed65929342a32e
 U drh
-Z 45e81044200c651866d6b14e1f654b51
+Z c8a8d9945ac3ddc516393bf70fb76d82
 # Remove this line to create a well-formed Fossil manifest.
index 0f63d3a2bb3dfac5df62f81e0330be465b96f619..74271f635a644e86b07113ed5aea60d8f0f25230 100644 (file)
@@ -1 +1 @@
-054a195125a273bab026ada5f07cc7c32818007027a1fd028ca59d2f179276d4
\ No newline at end of file
+3832b8a9ef84d9b53b48dfce9c1e724897cd7b3e05711e01675419655f894eac
\ No newline at end of file
index 028c3389e7ffd3fc12e6e8fa42057e5bc42fb993..4106bd899c830b581982c5aac140b93b57368545 100644 (file)
@@ -870,11 +870,46 @@ static int parseModifier(
     case '9': {
       double rRounder;
       int i;
-      for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
+      int Y,M,D,H,x;
+      for(n=1; z[n]; n++){
+        if( z[n]==':' ) break;
+        if( sqlite3Isspace(z[n]) ) break;
+        if( z[n]=='-' && n==5 && getDigits(&z[1], "40f", &Y)==1 ) break;
+      }
       if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){
         rc = 1;
         break;
       }
+      if( z[n]=='-' ){
+        /* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the
+        ** specified number of years, months, and days.  MM is limited to
+        ** the range 0-11 and DD is limited to 0-30.
+        */
+        if( z[0]!='+' && z[0]!='-' ) break;  /* Must start with +/- */
+        if( n!=5 ) break;                    /* Must be 4-digit YYYY */
+        if( getDigits(&z[1], "40f-20a-20d 20c", &Y, &M, &D, &H)!=4 ) break;
+        if( M>=12 ) break;                   /* M range 0..11 */
+        if( D>=31 ) break;                   /* D range 0..30 */
+        computeYMD_HMS(p);
+        p->validJD = 0;
+        if( z[0]=='-' ){
+          p->Y -= Y;
+          p->M -= M;
+          D = -D;
+        }else{
+          p->Y += Y;
+          p->M += M;
+        }
+        x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
+        p->Y += x;
+        p->M -= x*12;
+        computeJD(p);
+        p->validHMS = 0;
+        p->validYMD = 0;
+        p->iJD += (i64)D*86400000;
+        z = &z[12];
+        n = 2;
+      }
       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
@@ -916,7 +951,6 @@ static int parseModifier(
         ){
           switch( i ){
             case 4: { /* Special processing to add months */
-              int x;
               assert( strcmp(aXformType[i].zName,"month")==0 );
               computeYMD_HMS(p);
               p->M += (int)r;