Apply time filtering to "time grain" truncated dates
- [x] I have reproduced the issue with at least the latest released version of superset
- [x] I have checked the issue tracker for the same issue and I haven't found one similar
Superset version
v0.19.1
Expected results
Say I want to display the number of items purchased per week over the last 3 months with a bar chart. I choose a weekly time grain, and set the time window to start from "90 days ago"

I would expect the first bar, for the first week, to correspond to the number of items purchased for the whole week, not for the part of that week that happen to be within the 90-day time range.
SELECT DATE_TRUNC('week', purchase_timestamp) AS __timestamp,
COUNT(*) AS purchases
FROM purchase_table
WHERE DATE_TRUNC('week', purchase_timestamp) >= DATE_TRUNC('week', TIMESTAMP '2017-06-29 00:00:00')
AND DATE_TRUNC('week', purchase_timestamp) <= DATE_TRUNC('week', TIMESTAMP '2017-09-26 00:00:00')
GROUP BY DATE_TRUNC('week', purchase_timestamp)
Actual results
The first bar is truncated, and does not correspond to the whole week
SELECT DATE_TRUNC('week', purchase_timestamp) AS __timestamp,
COUNT(*) AS purchases
FROM purchase_table
WHERE purchase_timestamp >= '2017-06-29 00:00:00'
AND purchase_timestamp <= '2017-09-26 00:00:00'
GROUP BY DATE_TRUNC('week', purchase_timestamp)
I agreed that this is the desired behavior to get "full buckets"
I also found an issue with literal_column from SQLAlchemy that will escape the "%" symbol in the string. The final SQL will have two consecutive "%".

This issue is related to #617 . I tried to switch to the SQLAlchemy 1.2.0b3 and it works fine. So they already fix this issue in the latest version.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.