diff --git a/README_SMARTPL.md b/README_SMARTPL.md index 727d7f13..e6752fdc 100644 --- a/README_SMARTPL.md +++ b/README_SMARTPL.md @@ -162,9 +162,9 @@ One example of a valid date is a date in yyyy-mm-dd format: ``` There are also some special date keywords: -* `today`, `yesterday`, `last week`, `last month`, `last year` +* `today`, `yesterday`, `this week`, `last week`, `last month`, `last year` -These dates refer to the _start_ of that period; `today` means 00:00hrs of today, `last week` means the previous Monday 00:00hrs, `last month` is the first day of the previous month at 00:00hrs etc. +These dates refer to the _start_ of that period; `today` means 00:00hrs of today, `this week` means current Monday 00:00hrs, `last week` means the previous Monday 00:00hrs, `last month` is the first day of the previous month at 00:00hrs etc. A valid date can also be made by applying an interval to a date. Intervals can be defined as `days`, `weeks`, `months`, `years`. As an example, a valid date might be: diff --git a/src/parsers/smartpl_lexer.l b/src/parsers/smartpl_lexer.l index 01fc9825..8626cde6 100644 --- a/src/parsers/smartpl_lexer.l +++ b/src/parsers/smartpl_lexer.l @@ -122,6 +122,7 @@ limit { return SMARTPL_T_LIMIT; } {yyyymmdd} { yylval->str = strdup(yytext); return SMARTPL_T_DATE; } today { return (yylval->ival = SMARTPL_T_DATE_TODAY); } yesterday { return (yylval->ival = SMARTPL_T_DATE_YESTERDAY); } +this\ week { return (yylval->ival = SMARTPL_T_DATE_THISWEEK); } last\ week { return (yylval->ival = SMARTPL_T_DATE_LASTWEEK); } last\ month { return (yylval->ival = SMARTPL_T_DATE_LASTMONTH); } last\ year { return (yylval->ival = SMARTPL_T_DATE_LASTYEAR); } diff --git a/src/parsers/smartpl_parser.y b/src/parsers/smartpl_parser.y index 69747c39..be695c39 100644 --- a/src/parsers/smartpl_parser.y +++ b/src/parsers/smartpl_parser.y @@ -396,6 +396,8 @@ static void sql_from_ast(struct smartpl_result *result, struct result_part *part sql_append_recursive(result, part, a, "now', 'start of day", NULL, 0, SQL_APPEND_DATE_FIELD); break; case SMARTPL_T_DATE_YESTERDAY: sql_append_recursive(result, part, a, "now', 'start of day', '-1 day", NULL, 0, SQL_APPEND_DATE_FIELD); break; + case SMARTPL_T_DATE_THISWEEK: + sql_append_recursive(result, part, a, "now', 'start of day', 'weekday 0', '-7 days", NULL, 0, SQL_APPEND_DATE_FIELD); break; case SMARTPL_T_DATE_LASTWEEK: sql_append_recursive(result, part, a, "now', 'start of day', 'weekday 0', '-13 days", NULL, 0, SQL_APPEND_DATE_FIELD); break; case SMARTPL_T_DATE_LASTMONTH: @@ -505,6 +507,7 @@ static int result_set(struct smartpl_result *result, char *title, struct ast *cr %token SMARTPL_T_DATE %token SMARTPL_T_DATE_TODAY %token SMARTPL_T_DATE_YESTERDAY +%token SMARTPL_T_DATE_THISWEEK %token SMARTPL_T_DATE_LASTWEEK %token SMARTPL_T_DATE_LASTMONTH %token SMARTPL_T_DATE_LASTYEAR @@ -592,6 +595,7 @@ dateexpr: SMARTPL_T_DATE { $$ = ast_new(SMART daterelative: SMARTPL_T_DATE_TODAY | SMARTPL_T_DATE_YESTERDAY +| SMARTPL_T_DATE_THISWEEK | SMARTPL_T_DATE_LASTWEEK | SMARTPL_T_DATE_LASTMONTH | SMARTPL_T_DATE_LASTYEAR