From 1fe74f692e4542b4c8e1e9b9bd0e39c03b158f2d Mon Sep 17 00:00:00 2001 From: "D. Richard Hipp" Date: Sat, 2 Mar 2024 20:50:56 +0000 Subject: [PATCH] Change the magic time-interval names that do truncate-to-same-month to be "mnth" and "yr" - "month" and "year" without the vowels. --- src/date.c | 38 +++++++++++++++++++------------------- test/date.test | 9 +++++++++ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/date.c b/src/date.c index fd225d1e29..d4c3afdd38 100644 --- a/src/date.c +++ b/src/date.c @@ -626,18 +626,18 @@ static int toLocaltime( */ static const struct { u8 nName; /* Length of the name */ - char zName[9]; /* Name of the transformation */ + char zName[7]; /* 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 }, - { 8, "pg-month", 176546.0, 2592000.0 }, - { 7, "pg-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 }, }; /* @@ -958,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 ); @@ -970,26 +970,26 @@ static int parseModifier( ){ int targetMonth = 0; switch( i ){ - case 6: - case 4: { /* Special processing to add months */ - assert( strcmp(aXformType[i].zName,"month")==0 - || strcmp(aXformType[i].zName,"pg-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==6 ) targetMonth = p->M; + if( i==5 ) targetMonth = p->M; p->validJD = 0; r -= (int)r; break; } - case 7: - 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 - || strcmp(aXformType[i].zName,"pg-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; diff --git a/test/date.test b/test/date.test index d536c65fce..f0616f6570 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 -- 2.11.4.GIT