mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-24 13:13:17 -05:00
[smartpl] date 'interval' handling defered to db/not using potentially inaccurate time_t calcaulations
This commit is contained in:
parent
d31a8c1e05
commit
3dcd826513
@ -310,7 +310,7 @@ ordertag returns [ pANTLR3_STRING result ]
|
|||||||
;
|
;
|
||||||
|
|
||||||
dateval returns [ pANTLR3_STRING result ]
|
dateval returns [ pANTLR3_STRING result ]
|
||||||
@init { $result = 0; }
|
@init { $result = NULL; }
|
||||||
: DATE
|
: DATE
|
||||||
{
|
{
|
||||||
pANTLR3_UINT8 datval;
|
pANTLR3_UINT8 datval;
|
||||||
@ -347,10 +347,8 @@ dateval returns [ pANTLR3_STRING result ]
|
|||||||
| interval BEFORE DATE
|
| interval BEFORE DATE
|
||||||
{
|
{
|
||||||
pANTLR3_UINT8 datval;
|
pANTLR3_UINT8 datval;
|
||||||
char str[15];
|
|
||||||
|
|
||||||
datval = $DATE.text->chars;
|
datval = $DATE.text->chars;
|
||||||
sprintf(str, "\%d", $interval.result);
|
|
||||||
|
|
||||||
$result = $DATE.text->factory->newRaw($DATE.text->factory);
|
$result = $DATE.text->factory->newRaw($DATE.text->factory);
|
||||||
|
|
||||||
@ -376,16 +374,14 @@ dateval returns [ pANTLR3_STRING result ]
|
|||||||
}
|
}
|
||||||
|
|
||||||
$result->append8($result, "'-");
|
$result->append8($result, "'-");
|
||||||
$result->append8($result, str);
|
$result->append8($result, (const char *)$interval.result->chars);
|
||||||
$result->append8($result, " seconds', 'localtime'))");
|
$result->append8($result, "', 'localtime'))");
|
||||||
}
|
}
|
||||||
| interval AFTER DATE
|
| interval AFTER DATE
|
||||||
{
|
{
|
||||||
pANTLR3_UINT8 datval;
|
pANTLR3_UINT8 datval;
|
||||||
char str[15];
|
|
||||||
|
|
||||||
datval = $DATE.text->chars;
|
datval = $DATE.text->chars;
|
||||||
sprintf(str, "\%d", $interval.result);
|
|
||||||
|
|
||||||
$result = $DATE.text->factory->newRaw($DATE.text->factory);
|
$result = $DATE.text->factory->newRaw($DATE.text->factory);
|
||||||
|
|
||||||
@ -411,52 +407,29 @@ dateval returns [ pANTLR3_STRING result ]
|
|||||||
}
|
}
|
||||||
|
|
||||||
$result->append8($result, "'+");
|
$result->append8($result, "'+");
|
||||||
$result->append8($result, str);
|
$result->append8($result, (const char *)$interval.result->chars);
|
||||||
$result->append8($result, " seconds', 'localtime'))");
|
$result->append8($result, "', 'localtime'))");
|
||||||
}
|
}
|
||||||
| interval AGO
|
| interval AGO
|
||||||
{
|
{
|
||||||
char str[15];
|
|
||||||
sprintf(str, "\%d", $interval.result);
|
|
||||||
|
|
||||||
$result = $AGO.text->factory->newRaw($AGO.text->factory);
|
$result = $AGO.text->factory->newRaw($AGO.text->factory);
|
||||||
|
|
||||||
$result->append8($result, "strftime('\%s', datetime('now', 'start of day', ");
|
$result->append8($result, "strftime('\%s', datetime('now', 'start of day', ");
|
||||||
$result->append8($result, "'-");
|
$result->append8($result, "'-");
|
||||||
$result->append8($result, str);
|
$result->append8($result, (const char *)$interval.result->chars);
|
||||||
$result->append8($result, " seconds', 'localtime'))");
|
$result->append8($result, "', 'localtime'))");
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
interval returns [ int result ]
|
interval returns [ pANTLR3_STRING result ]
|
||||||
@init { $result = 0; }
|
@init { $result = NULL; }
|
||||||
: INT DATINTERVAL
|
: INT DATINTERVAL
|
||||||
{
|
{
|
||||||
pANTLR3_UINT8 interval;
|
$result = $DATINTERVAL.text->factory->newRaw($DATINTERVAL.text->factory);
|
||||||
|
$result->append8($result, (const char *)$INT.text->chars);
|
||||||
$result = atoi((const char *)$INT.text->chars);
|
$result->append8($result, " ");
|
||||||
interval = $DATINTERVAL.text->chars;
|
$result->append8($result, (const char *)$DATINTERVAL.text->chars);
|
||||||
|
return $result;
|
||||||
if (strcmp((char *)interval, "days") == 0)
|
|
||||||
{
|
|
||||||
$result = $result * 24 * 3600;
|
|
||||||
}
|
|
||||||
else if (strcmp((char *)interval, "weeks") == 0)
|
|
||||||
{
|
|
||||||
$result = $result * 24 * 3600 * 7;
|
|
||||||
}
|
|
||||||
else if (strcmp((char *)interval, "months") == 0)
|
|
||||||
{
|
|
||||||
$result = $result * 24 * 3600 * 30;
|
|
||||||
}
|
|
||||||
else if (strcmp((char *)interval, "weeks") == 0)
|
|
||||||
{
|
|
||||||
$result = $result * 24 * 3600 * 365;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user