changeset 488:9f5b08b205bf

Allow numeric argument for day(s)/week(s)/month(s)/year(s)
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 15 Feb 2018 12:24:39 +0859
parents b17bdc798dc5
children 075897fee2c0
files s4-blog.sh
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/s4-blog.sh	Tue Feb 06 11:22:51 2018 +0900
+++ b/s4-blog.sh	Thu Feb 15 12:24:39 2018 +0859
@@ -786,6 +786,7 @@
     kc="ar.rowid = $rowid"
   else
     for k in `echo "$kwd" | sed "s/'/''/g"`; do		# With wrap quotes
+      ctime=""
       if expr x"$k" : 'x@[><= ]*[1-9][][0-9]*-[][0-9:-]*$' >/dev/null >&2; then
 	# '@<2016-10-10'	-> ctime < '2016-10-10'
 	# '@>=2016-10-10'	-> ctime >= '2016-10-10'
@@ -800,15 +801,23 @@
 	##### kwdgrp=" GROUP BY a.blogid"   ## Add this to lessen results
       elif [ x"$k" = x"@today" -o x"$k" = x"@今日" ]; then
 	ctime=`date +%F`
-	kc=$kc${kc:+" AND "}"ctime GLOB '${ctime}*'"
+      elif n=`expr x"$k" : 'x@\([0-9]*\)days*'` >/dev/null >&2; then
+	ctime=`query "SELECT datetime('now', 'localtime', '-$n days');"`
       elif [ x"$k" = x"@week" ]; then
 	ctime=`query "SELECT datetime('now', 'localtime', '-7 days');"`
-	kc=$kc${kc:+" AND "}"ctime > '${ctime}'"
+      elif n=`expr x"$k" : 'x@\([0-9]*\)weeks*'` >/dev/null >&2; then
+	n=$((n * 7))
+	ctime=`query "SELECT datetime('now', 'localtime', '-$n days');"`
       elif [ x"$k" = x"@month" ]; then
 	ctime=`query "SELECT datetime('now', 'localtime', '-1 month');"`
-	kc=$kc${kc:+" AND "}"ctime > '${ctime}'"
+      elif n=`expr x"$k" : 'x@\([0-9]*\)months*'` >/dev/null >&2; then
+	ctime=`query "SELECT datetime('now', 'localtime', '-$n month');"`
       elif [ x"$k" = x"@year" ]; then
 	ctime=`query "SELECT datetime('now', 'localtime', '-1 year');"`
+      elif n=`expr x"$k" : 'x@\([0-9]*\)years*'` >/dev/null >&2; then
+	ctime=`query "SELECT datetime('now', 'localtime', '-$n year');"`
+      fi
+      if [ -n "$ctime" ]; then
 	kc=$kc${kc:+" AND "}"ctime > '${ctime}'"
       else
 	kc=$kc${kc:+" AND "}"content LIKE '%$k%'"

yatex.org