mirror of https://github.com/apache/superset.git
fix(explore): refine previous calendar range (#12308)
This commit is contained in:
parent
90ac8d02c6
commit
9eb911dca3
|
@ -1502,19 +1502,19 @@ def get_since_until(
|
|||
and time_range.startswith("previous calendar week")
|
||||
and separator not in time_range
|
||||
):
|
||||
time_range = "DATETRUNC(DATEADD(DATETIME('today'), -1, WEEK), WEEK) : LASTDAY(DATEADD(DATETIME('today'), -1, WEEK), WEEK)" # pylint: disable=line-too-long
|
||||
time_range = "DATETRUNC(DATEADD(DATETIME('today'), -1, WEEK), WEEK) : DATETRUNC(DATETIME('today'), WEEK)" # pylint: disable=line-too-long
|
||||
if (
|
||||
time_range
|
||||
and time_range.startswith("previous calendar month")
|
||||
and separator not in time_range
|
||||
):
|
||||
time_range = "DATETRUNC(DATEADD(DATETIME('today'), -1, MONTH), MONTH) : LASTDAY(DATEADD(DATETIME('today'), -1, MONTH), MONTH)" # pylint: disable=line-too-long
|
||||
time_range = "DATETRUNC(DATEADD(DATETIME('today'), -1, MONTH), MONTH) : DATETRUNC(DATETIME('today'), MONTH)" # pylint: disable=line-too-long
|
||||
if (
|
||||
time_range
|
||||
and time_range.startswith("previous calendar year")
|
||||
and separator not in time_range
|
||||
):
|
||||
time_range = "DATETRUNC(DATEADD(DATETIME('today'), -1, YEAR), YEAR) : LASTDAY(DATEADD(DATETIME('today'), -1, YEAR), YEAR)" # pylint: disable=line-too-long
|
||||
time_range = "DATETRUNC(DATEADD(DATETIME('today'), -1, YEAR), YEAR) : DATETRUNC(DATETIME('today'), YEAR)" # pylint: disable=line-too-long
|
||||
|
||||
if time_range and separator in time_range:
|
||||
time_range_lookup = [
|
||||
|
|
|
@ -762,15 +762,15 @@ class TestUtils(SupersetTestCase):
|
|||
self.assertEqual(result, expected)
|
||||
|
||||
result = get_since_until("previous calendar week")
|
||||
expected = datetime(2016, 10, 31, 0, 0, 0), datetime(2016, 11, 6, 0, 0, 0)
|
||||
expected = datetime(2016, 10, 31, 0, 0, 0), datetime(2016, 11, 7, 0, 0, 0)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
result = get_since_until("previous calendar month")
|
||||
expected = datetime(2016, 10, 1, 0, 0, 0), datetime(2016, 10, 31, 0, 0, 0)
|
||||
expected = datetime(2016, 10, 1, 0, 0, 0), datetime(2016, 11, 1, 0, 0, 0)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
result = get_since_until("previous calendar year")
|
||||
expected = datetime(2015, 1, 1, 0, 0, 0), datetime(2015, 12, 31, 0, 0, 0)
|
||||
expected = datetime(2015, 1, 1, 0, 0, 0), datetime(2016, 1, 1, 0, 0, 0)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
|
|
Loading…
Reference in New Issue