]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Proof-of-concept for new time-interval operator "pg-month" and "pg-year" that
authordrh <>
Sat, 2 Mar 2024 13:38:46 +0000 (13:38 +0000)
committerdrh <>
Sat, 2 Mar 2024 13:38:46 +0000 (13:38 +0000)
use the truncate-to-month algorithm for month overflow instead of the
wrap-to-next-month algorithm that is used by SQLite by default.

FossilOrigin-Name: b606c0965788f56547435c9318b60e32990877e14a9640d887f33f39d1bdc7c3

manifest
manifest.uuid
src/date.c

index 28b15c7a433b07ac3a545adc351a0110a9c0ee1d..9ca9c979c5d9ab76aec095d5cc9bf216697b2e23 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\stwo\s-Werror=lto-type-mismatch\swarnings\sreported\sin\s[forum:ef62b57bd5|forum\spost\sef62b57bd5].
-D 2024-02-29T10:55:02.008
+C Proof-of-concept\sfor\snew\stime-interval\soperator\s"pg-month"\sand\s"pg-year"\sthat\nuse\sthe\struncate-to-month\salgorithm\sfor\smonth\soverflow\sinstead\sof\sthe\nwrap-to-next-month\salgorithm\sthat\sis\sused\sby\sSQLite\sby\sdefault.
+D 2024-03-02T13:38:46.691
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -696,7 +696,7 @@ F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f
 F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490
 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
 F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b
-F src/date.c 90df32c2d8b2a38dd2e83d32e47802629305c4882fb2ec75c9ecdcd75b68bcb2
+F src/date.c f0bde50092368a0eaff79e25ab24c3c91763859adffd91af6bf47cbc13cc7512
 F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782
 F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43
 F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500
@@ -2176,9 +2176,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P d51c699ae413215d534f954c129691ef5d95d540dc5d4304cbba576c976d931c 29f94610dc8319709b8d3726a60e2a7a33ffbf4998c681f772da26c9701cc0b0
-R 728f9a968510fa9cb95ea7ce7eec45f1
-T +closed 29f94610dc8319709b8d3726a60e2a7a33ffbf4998c681f772da26c9701cc0b0 Closed\sby\sintegrate-merge.
-U stephan
-Z 37dee8fa6539319388e07ab4c515c697
+P 803481f25020f3c25941f1e7d1a8071937820dea951e8798198b0b0fa3fb48ce
+R 736136842d7746223f17212059cfe765
+T *branch * month-truncate
+T *sym-month-truncate *
+T -sym-trunk *
+U drh
+Z e1892067371eb0569faf26bcf07d7955
 # Remove this line to create a well-formed Fossil manifest.
index 2f2c96f612a757504d29f287cd1aa4a703dee741..5a462d35fa206aa1757720e718796020e3f8e2d1 100644 (file)
@@ -1 +1 @@
-803481f25020f3c25941f1e7d1a8071937820dea951e8798198b0b0fa3fb48ce
\ No newline at end of file
+b606c0965788f56547435c9318b60e32990877e14a9640d887f33f39d1bdc7c3
\ No newline at end of file
index 026d83391aa55417e230f4e288676ae700bb3cbb..fd225d1e290e062f91ad7bcbf0cc17219ee95509 100644 (file)
@@ -626,16 +626,18 @@ static int toLocaltime(
 */
 static const struct {
   u8 nName;           /* Length of the name */
-  char zName[7];      /* Name of the transformation */
+  char zName[9];      /* Name of the transformation */
   float rLimit;       /* Maximum NNN value for this transform */
   float rXform;       /* Constant used for this transform */
 } aXformType[] = {
-  { 6, "second", 4.6427e+14,       1.0  },
-  { 6, "minute", 7.7379e+12,      60.0  },
-  { 4, "hour",   1.2897e+11,    3600.0  },
-  { 3, "day",    5373485.0,    86400.0  },
-  { 5, "month",  176546.0,   2592000.0  },
-  { 4, "year",   14713.0,   31536000.0  },
+  { 6, "second",   4.6427e+14,       1.0  },
+  { 6, "minute",   7.7379e+12,      60.0  },
+  { 4, "hour",     1.2897e+11,    3600.0  },
+  { 3, "day",      5373485.0,    86400.0  },
+  { 5, "month",    176546.0,   2592000.0  },
+  { 4, "year",     14713.0,   31536000.0  },
+  { 8, "pg-month", 176546.0,   2592000.0  },
+  { 7, "pg-year",  14713.0,   31536000.0  },
 };
 
 /*
@@ -966,22 +968,31 @@ static int parseModifier(
          && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
          && r>-aXformType[i].rLimit && r<aXformType[i].rLimit
         ){
+          int targetMonth = 0;
           switch( i ){
+            case 6:
             case 4: { /* Special processing to add months */
-              assert( strcmp(aXformType[i].zName,"month")==0 );
+              assert( strcmp(aXformType[i].zName,"month")==0
+                   || strcmp(aXformType[i].zName,"pg-month")==0 );
               computeYMD_HMS(p);
               p->M += (int)r;
               x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
               p->Y += x;
               p->M -= x*12;
+              assert( p->M>=1 && p->M<=12 );
+              if( i==6 ) targetMonth = p->M;
               p->validJD = 0;
               r -= (int)r;
               break;
             }
+            case 7:
             case 5: { /* Special processing to add years */
               int y = (int)r;
-              assert( strcmp(aXformType[i].zName,"year")==0 );
+              assert( strcmp(aXformType[i].zName,"year")==0
+                   || strcmp(aXformType[i].zName,"pg-year")==0 );
               computeYMD_HMS(p);
+              assert( p->M>=1 && p->M<=12 );
+              if( i==7 ) targetMonth = p->M;
               p->Y += y;
               p->validJD = 0;
               r -= (int)r;
@@ -989,6 +1000,12 @@ static int parseModifier(
             }
           }
           computeJD(p);
+          if( targetMonth>0 ){
+            p->validYMD = 0;
+            computeYMD(p);
+            if( p->M==targetMonth+1 ) p->iJD -= p->D*86400000;
+            p->validYMD = 0;
+          }
           p->iJD += (sqlite3_int64)(r*1000.0*aXformType[i].rXform + rRounder);
           rc = 0;
           break;