Fossil SCM
Enhance the /timeline query parameter parsing so that the ymd=, ym=, and yw= query parameters can optionally omit the date punctuation.
Commit
9bdda2047fbde3d82c9ff612781d4a771e4c8fcf9cf7d26ee3088aae2b5ee124
Parent
40c40f7fe6136d5…
1 file changed
+43
-1
+43
-1
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -1413,10 +1413,49 @@ | ||
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | 1415 | /* If execution reaches this point, the pattern was empty. Return NULL. */ |
| 1416 | 1416 | return 0; |
| 1417 | 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 | + | |
| 1418 | 1457 | |
| 1419 | 1458 | /* |
| 1420 | 1459 | ** WEBPAGE: timeline |
| 1421 | 1460 | ** |
| 1422 | 1461 | ** Query parameters: |
| @@ -1930,14 +1969,16 @@ | ||
| 1930 | 1969 | } |
| 1931 | 1970 | if( bisectLocal || zBisect!=0 ){ |
| 1932 | 1971 | blob_append_sql(&cond, " AND event.objid IN (SELECT rid FROM bilog) "); |
| 1933 | 1972 | } |
| 1934 | 1973 | if( zYearMonth ){ |
| 1974 | + zYearMonth = timeline_expand_datetime(zYearMonth); | |
| 1935 | 1975 | blob_append_sql(&cond, " AND %Q=strftime('%%Y-%%m',event.mtime) ", |
| 1936 | - zYearMonth); | |
| 1976 | + zYearMonth); | |
| 1937 | 1977 | } |
| 1938 | 1978 | else if( zYearWeek ){ |
| 1979 | + zYearWeek = timeline_expand_datetime(zYearWeek); | |
| 1939 | 1980 | char *z = db_text(0, "SELECT strftime('%%Y-%%W',%Q)", zYearWeek); |
| 1940 | 1981 | if( z && z[0] ){ |
| 1941 | 1982 | zYearWeekStart = db_text(0, "SELECT date(%Q,'-6 days','weekday 1')", |
| 1942 | 1983 | zYearWeek); |
| 1943 | 1984 | zYearWeek = z; |
| @@ -1959,10 +2000,11 @@ | ||
| 1959 | 2000 | blob_append_sql(&cond, " AND %Q=strftime('%%Y-%%W',event.mtime) ", |
| 1960 | 2001 | zYearWeek); |
| 1961 | 2002 | nEntry = -1; |
| 1962 | 2003 | } |
| 1963 | 2004 | else if( zDay ){ |
| 2005 | + zDay = timeline_expand_datetime(zDay); | |
| 1964 | 2006 | zDay = db_text(0, "SELECT date(%Q)", zDay); |
| 1965 | 2007 | if( zDay==0 || zDay[0]==0 ){ |
| 1966 | 2008 | zDay = db_text(0, "SELECT date('now')"); |
| 1967 | 2009 | } |
| 1968 | 2010 | blob_append_sql(&cond, " AND %Q=date(event.mtime) ", |
| 1969 | 2011 |
| --- 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 |