aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifest18
-rw-r--r--manifest.uuid2
-rw-r--r--src/date.c39
-rw-r--r--test/date.test9
4 files changed, 47 insertions, 21 deletions
diff --git a/manifest b/manifest
index 28b15c7a4..8e0dc8a66 100644
--- 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 New\sdate/time\smodifiers\s"mnth"\sand\s"yr"\swork\slike\s"month"\sand\s"year"\sbut\nresolve\sday-of-month\soverflow\sby\struncating\srather\sthan\srolling\sover\sinto\nthe\snext\smonth.\s[forum:/forumpost/232d1abb5d|Forum\sthread\s232d1abb5d]
+D 2024-03-02T21:02:41.160
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 89083264f1832e2bb892d6b313a6c642a5cd730cfcc89574019aa06c69192dcd
F src/dbpage.c 80e46e1df623ec40486da7a5086cb723b0275a6e2a7b01d9f9b5da0f04ba2782
F src/dbstat.c 3b677254d512fcafd4d0b341bf267b38b235ccfddbef24f9154e19360fa22e43
F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500
@@ -1042,7 +1042,7 @@ F test/ctime.test 340f362f41f92972bbd71f44e10569a5cc694062b692231bd08aa6fe6c1c47
F test/cursorhint.test 05cf0febe5c5f8a31f199401fd1c9322249e753950d55f26f9d5aca61408a270
F test/cursorhint2.test 6f3aa9cb19e7418967a10ec6905209bcbb5968054da855fc36c8beee9ae9c42f
F test/dataversion1.test 6e5e86ac681f0782e766ebcb56c019ae001522d114e0e111e5ebf68ccf2a7bb8
-F test/date.test b1a5208e6a9c390cf1d1fa4e38a910386b427b0e27046901c6b0fb995d19800e
+F test/date.test 9583b421058d8366a06d4a07135ced29b64e31b5e7dafd03a2040bf84ef69adb
F test/date2.test 7e12ec14aaf4d5e6294b4ba140445b0eca06ea50062a9c3a69c4ee13d0b6f8b1
F test/date3.test a1b77abf05c6772fe5ca2337cac1398892f2a41e62bce7e6be0f4a08a0e64ae5
F test/date4.test 75dc8401e8c0639a228cd26a6eaa4ff5ea8ccda912b9853d1c9462c476670e17
@@ -2176,9 +2176,9 @@ 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 296b46c529d79385d7f4db2c789254a992c01ff66fe8ba6d3a3ce4aaac0203fb
+R e86e5c292ead4f22cefd158cafe4f8bc
+T +closed 296b46c529d79385d7f4db2c789254a992c01ff66fe8ba6d3a3ce4aaac0203fb
+U drh
+Z b02519e2fed4e4d80162d593e160efa1
# Remove this line to create a well-formed Fossil manifest.
diff --git a/manifest.uuid b/manifest.uuid
index 2f2c96f61..d954bb7e4 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-803481f25020f3c25941f1e7d1a8071937820dea951e8798198b0b0fa3fb48ce \ No newline at end of file
+5d392c16bb5658bc92f60d250ab82c45cc109e32d58a073498c9a487b8625e96 \ No newline at end of file
diff --git a/src/date.c b/src/date.c
index 026d83391..d4c3afdd3 100644
--- a/src/date.c
+++ b/src/date.c
@@ -630,12 +630,14 @@ static const struct {
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 },
+ /* 0 */ { 6, "second", 4.6427e+14, 1.0 },
+ /* 1 */ { 6, "minute", 7.7379e+12, 60.0 },
+ /* 2 */ { 4, "hour", 1.2897e+11, 3600.0 },
+ /* 3 */ { 3, "day", 5373485.0, 86400.0 },
+ /* 4 */ { 5, "month", 176546.0, 30.0*86400.0 },
+ /* 5 */ { 4, "mnth", 176546.0, 30.0*86400.0 },
+ /* 6 */ { 4, "year", 14713.0, 365.0*86400.0 },
+ /* 7 */ { 2, "yr", 14713.0, 365.0*86400.0 },
};
/*
@@ -956,7 +958,7 @@ static int parseModifier(
z += n;
while( sqlite3Isspace(*z) ) z++;
n = sqlite3Strlen30(z);
- if( n>10 || n<3 ) break;
+ if( n>10 || n<2 ) break;
if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--;
computeJD(p);
assert( rc==1 );
@@ -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 4: { /* Special processing to add months */
- assert( strcmp(aXformType[i].zName,"month")==0 );
+ case 4:
+ case 5: { /* Special processing to add months */
+ assert( strcmp(aXformType[4].zName,"month")==0 );
+ assert( strcmp(aXformType[5].zName,"mnth")==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==5 ) targetMonth = p->M;
p->validJD = 0;
r -= (int)r;
break;
}
- case 5: { /* Special processing to add years */
+ case 6:
+ case 7: { /* Special processing to add years */
int y = (int)r;
- assert( strcmp(aXformType[i].zName,"year")==0 );
+ assert( strcmp(aXformType[6].zName,"year")==0 );
+ assert( strcmp(aXformType[7].zName,"yr")==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;
diff --git a/test/date.test b/test/date.test
index d536c65fc..f0616f657 100644
--- a/test/date.test
+++ b/test/date.test
@@ -148,6 +148,15 @@ datetest 2.51 {datetime('2003-10-22 12:24','nonsense')} NULL
datetest 2.60 {datetime('2023-02-31')} {2023-03-03 00:00:00}
+datetest 2.70 {date('2024-01-31','+1 month')} {2024-03-02}
+datetest 2.71 {date('2024-01-31','+1 mnth')} {2024-02-29}
+datetest 2.72 {date('2023-01-31','+1 month')} {2023-03-03}
+datetest 2.73 {date('2023-01-31','+1 mnth')} {2023-02-28}
+datetest 2.74 {date('2024-02-29','+1 year')} {2025-03-01}
+datetest 2.75 {date('2024-02-29','+1 yr')} {2025-02-28}
+datetest 2.76 {date('2024-02-29','-110 years')} {1914-03-01}
+datetest 2.77 {date('2024-02-29','-110 yrs')} {1914-02-28}
+
datetest 3.1 {strftime('%d','2003-10-31 12:34:56.432')} 31
datetest 3.2.1 {strftime('pre%fpost','2003-10-31 12:34:56.432')} pre56.432post
datetest 3.2.2 {strftime('%f','2003-10-31 12:34:59.9999999')} 59.999