Fossil SCM

Enhance the /timeline query parameter parsing so that the ymd=, ym=, and yw= query parameters can optionally omit the date punctuation.

drh 2019-04-19 18:55 trunk
Commit 9bdda2047fbde3d82c9ff612781d4a771e4c8fcf9cf7d26ee3088aae2b5ee124
1 file changed +43 -1
+43 -1
--- src/timeline.c
+++ src/timeline.c
@@ -1413,10 +1413,49 @@
14131413
}
14141414
14151415
/* If execution reaches this point, the pattern was empty. Return NULL. */
14161416
return 0;
14171417
}
1418
+
1419
+/*
1420
+** Similar to fossil_expand_datetime()
1421
+**
1422
+** Add missing "-" characters into a date/time. Examples:
1423
+**
1424
+** 20190419 => 2019-04-19
1425
+** 201904 => 2019-04
1426
+*/
1427
+const char *timeline_expand_datetime(const char *zIn){
1428
+ static char zEDate[20];
1429
+ static const char aPunct[] = { 0, 0, '-', '-', ' ', ':', ':' };
1430
+ int n = (int)strlen(zIn);
1431
+ int i, j;
1432
+
1433
+ /* Only three forms allowed:
1434
+ ** (1) YYYYMMDD
1435
+ ** (2) YYYYMM
1436
+ ** (3) YYYYWW
1437
+ */
1438
+ if( n!=8 && n!=6 ) return zIn;
1439
+
1440
+ /* Every character must be a digit */
1441
+ for(i=0; fossil_isdigit(zIn[i]); i++){}
1442
+ if( i!=n ) return zIn;
1443
+
1444
+ /* Expand the date */
1445
+ for(i=j=0; zIn[i]; i++){
1446
+ if( i>=4 && (i%2)==0 ){
1447
+ zEDate[j++] = aPunct[i/2];
1448
+ }
1449
+ zEDate[j++] = zIn[i];
1450
+ }
1451
+ zEDate[j] = 0;
1452
+
1453
+ /* It looks like this may be a date. Return it with punctuation added. */
1454
+ return zEDate;
1455
+}
1456
+
14181457
14191458
/*
14201459
** WEBPAGE: timeline
14211460
**
14221461
** Query parameters:
@@ -1930,14 +1969,16 @@
19301969
}
19311970
if( bisectLocal || zBisect!=0 ){
19321971
blob_append_sql(&cond, " AND event.objid IN (SELECT rid FROM bilog) ");
19331972
}
19341973
if( zYearMonth ){
1974
+ zYearMonth = timeline_expand_datetime(zYearMonth);
19351975
blob_append_sql(&cond, " AND %Q=strftime('%%Y-%%m',event.mtime) ",
1936
- zYearMonth);
1976
+ zYearMonth);
19371977
}
19381978
else if( zYearWeek ){
1979
+ zYearWeek = timeline_expand_datetime(zYearWeek);
19391980
char *z = db_text(0, "SELECT strftime('%%Y-%%W',%Q)", zYearWeek);
19401981
if( z && z[0] ){
19411982
zYearWeekStart = db_text(0, "SELECT date(%Q,'-6 days','weekday 1')",
19421983
zYearWeek);
19431984
zYearWeek = z;
@@ -1959,10 +2000,11 @@
19592000
blob_append_sql(&cond, " AND %Q=strftime('%%Y-%%W',event.mtime) ",
19602001
zYearWeek);
19612002
nEntry = -1;
19622003
}
19632004
else if( zDay ){
2005
+ zDay = timeline_expand_datetime(zDay);
19642006
zDay = db_text(0, "SELECT date(%Q)", zDay);
19652007
if( zDay==0 || zDay[0]==0 ){
19662008
zDay = db_text(0, "SELECT date('now')");
19672009
}
19682010
blob_append_sql(&cond, " AND %Q=date(event.mtime) ",
19692011
--- src/timeline.c
+++ src/timeline.c
@@ -1413,10 +1413,49 @@
1413 }
1414
1415 /* If execution reaches this point, the pattern was empty. Return NULL. */
1416 return 0;
1417 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1418
1419 /*
1420 ** WEBPAGE: timeline
1421 **
1422 ** Query parameters:
@@ -1930,14 +1969,16 @@
1930 }
1931 if( bisectLocal || zBisect!=0 ){
1932 blob_append_sql(&cond, " AND event.objid IN (SELECT rid FROM bilog) ");
1933 }
1934 if( zYearMonth ){
 
1935 blob_append_sql(&cond, " AND %Q=strftime('%%Y-%%m',event.mtime) ",
1936 zYearMonth);
1937 }
1938 else if( zYearWeek ){
 
1939 char *z = db_text(0, "SELECT strftime('%%Y-%%W',%Q)", zYearWeek);
1940 if( z && z[0] ){
1941 zYearWeekStart = db_text(0, "SELECT date(%Q,'-6 days','weekday 1')",
1942 zYearWeek);
1943 zYearWeek = z;
@@ -1959,10 +2000,11 @@
1959 blob_append_sql(&cond, " AND %Q=strftime('%%Y-%%W',event.mtime) ",
1960 zYearWeek);
1961 nEntry = -1;
1962 }
1963 else if( zDay ){
 
1964 zDay = db_text(0, "SELECT date(%Q)", zDay);
1965 if( zDay==0 || zDay[0]==0 ){
1966 zDay = db_text(0, "SELECT date('now')");
1967 }
1968 blob_append_sql(&cond, " AND %Q=date(event.mtime) ",
1969
--- src/timeline.c
+++ src/timeline.c
@@ -1413,10 +1413,49 @@
1413 }
1414
1415 /* If execution reaches this point, the pattern was empty. Return NULL. */
1416 return 0;
1417 }
1418
1419 /*
1420 ** Similar to fossil_expand_datetime()
1421 **
1422 ** Add missing "-" characters into a date/time. Examples:
1423 **
1424 ** 20190419 => 2019-04-19
1425 ** 201904 => 2019-04
1426 */
1427 const char *timeline_expand_datetime(const char *zIn){
1428 static char zEDate[20];
1429 static const char aPunct[] = { 0, 0, '-', '-', ' ', ':', ':' };
1430 int n = (int)strlen(zIn);
1431 int i, j;
1432
1433 /* Only three forms allowed:
1434 ** (1) YYYYMMDD
1435 ** (2) YYYYMM
1436 ** (3) YYYYWW
1437 */
1438 if( n!=8 && n!=6 ) return zIn;
1439
1440 /* Every character must be a digit */
1441 for(i=0; fossil_isdigit(zIn[i]); i++){}
1442 if( i!=n ) return zIn;
1443
1444 /* Expand the date */
1445 for(i=j=0; zIn[i]; i++){
1446 if( i>=4 && (i%2)==0 ){
1447 zEDate[j++] = aPunct[i/2];
1448 }
1449 zEDate[j++] = zIn[i];
1450 }
1451 zEDate[j] = 0;
1452
1453 /* It looks like this may be a date. Return it with punctuation added. */
1454 return zEDate;
1455 }
1456
1457
1458 /*
1459 ** WEBPAGE: timeline
1460 **
1461 ** Query parameters:
@@ -1930,14 +1969,16 @@
1969 }
1970 if( bisectLocal || zBisect!=0 ){
1971 blob_append_sql(&cond, " AND event.objid IN (SELECT rid FROM bilog) ");
1972 }
1973 if( zYearMonth ){
1974 zYearMonth = timeline_expand_datetime(zYearMonth);
1975 blob_append_sql(&cond, " AND %Q=strftime('%%Y-%%m',event.mtime) ",
1976 zYearMonth);
1977 }
1978 else if( zYearWeek ){
1979 zYearWeek = timeline_expand_datetime(zYearWeek);
1980 char *z = db_text(0, "SELECT strftime('%%Y-%%W',%Q)", zYearWeek);
1981 if( z && z[0] ){
1982 zYearWeekStart = db_text(0, "SELECT date(%Q,'-6 days','weekday 1')",
1983 zYearWeek);
1984 zYearWeek = z;
@@ -1959,10 +2000,11 @@
2000 blob_append_sql(&cond, " AND %Q=strftime('%%Y-%%W',event.mtime) ",
2001 zYearWeek);
2002 nEntry = -1;
2003 }
2004 else if( zDay ){
2005 zDay = timeline_expand_datetime(zDay);
2006 zDay = db_text(0, "SELECT date(%Q)", zDay);
2007 if( zDay==0 || zDay[0]==0 ){
2008 zDay = db_text(0, "SELECT date('now')");
2009 }
2010 blob_append_sql(&cond, " AND %Q=date(event.mtime) ",
2011

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button