msyavuz commented on code in PR #37098:
URL: https://github.com/apache/superset/pull/37098#discussion_r2693664590
##########
superset/utils/date_parser.py:
##########
@@ -415,13 +482,31 @@ def get_since_until( # pylint:
disable=too-many-arguments,too-many-locals,too-m
):
time_range = "DATETRUNC(DATEADD(DATETIME('today'), 0, YEAR), YEAR) :
DATETRUNC(DATEADD(DATETIME('today'), 1, YEAR), YEAR)" # noqa: E501
+ # Handle "first [subunit] of [scope] [unit]" patterns that produce a range
+ # e.g., "first week of this year" -> returns start of year to end of first
week
+ # e.g., "first month of this quarter" -> returns start of first month to
end
+ # Note: "day" is NOT included as a subunit here because "first day of X"
should
+ # return a single date, not a range. Those are handled in
time_range_lookup below.
+ if time_range and separator not in time_range:
+ nth_subunit_pattern = (
+ r"^(first|1st)\s{1,5}"
+ r"(week|month|quarter)\s{1,5}of\s{1,5}"
+ r"(?:(this|last|next|prior)\s{1,5})?"
+ r"(?:the\s{1,5})?"
+ r"(week|month|quarter|year)$"
+ )
+ match = re.search(nth_subunit_pattern, time_range, re.IGNORECASE)
+ if match:
+ ordinal, subunit, scope, unit = match.groups()
+ time_range = handle_nth_of(ordinal, subunit, scope, unit,
relative_start)
+
if time_range and separator in time_range:
time_range_lookup = [
(
r"^(start of|beginning of|end of)\s{1,5}"
r"(this|last|next|prior)\s{1,5}"
r"([0-9]+)?\s{0,5}"
- r"(day|week|month|quarter|year)s?$", # Matches phrases like
"start of next month" # noqa: E501
+ r"(day|week|month|quarter|year)s?$", # Matches "start of next
month" # noqa: E501
Review Comment:
Reminder that this was probably deleted by mistake
##########
superset/utils/date_parser.py:
##########
@@ -430,10 +515,32 @@ def get_since_until( # pylint:
disable=too-many-arguments,too-many-locals,too-m
get_relative_base(unit, relative_start),
),
),
+ (
+ # Pattern for "first of [scope] [unit]" - single date
+ # e.g., "first of this month", "first of last year"
+ r"^(first|1st)\s{1,5}"
+ r"(?:day\s{1,5})?of\s{1,5}"
+ r"(this|last|next|prior)\s{1,5}"
+ r"(day|week|month|quarter|year)s?$",
+ lambda ordinal, scope, unit: handle_nth_of(
+ ordinal, None, scope, unit, relative_start
+ ),
+ ),
+ (
+ # Pattern for "first of the [unit]" - single date with default
scope
+ # e.g., "first of the month", "first day of the year"
+ r"^(first|1st)\s{1,5}"
+ r"(?:day\s{1,5})?of\s{1,5}"
+ r"(?:the\s{1,5})?"
+ r"(week|month|quarter|year)$",
+ lambda ordinal, unit: handle_nth_of(
+ ordinal, None, None, unit, relative_start
+ ),
+ ),
(
r"^(this|last|next|prior)\s{1,5}"
r"([0-9]+)?\s{0,5}"
- r"(second|minute|day|week|month|quarter|year)s?$", # Matches
"next 5 days" or "last 2 weeks" # noqa: E501
+ r"(second|minute|day|week|month|quarter|year)s?$", # Matches
"next 5 days" # noqa: E501
Review Comment:
Ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]