korbit-ai[bot] commented on code in PR #31867:
URL: https://github.com/apache/superset/pull/31867#discussion_r1916325868


##########
superset/utils/date_parser.py:
##########
@@ -143,6 +143,70 @@ def parse_past_timedelta(
     )
 
 
+def get_relative_base(unit: str, relative_start: str | None = None) -> str:
+    """
+    Determine the base time (`relative_start`) based on granularity and user 
input.
+
+    Args:
+        unit (str): The time unit (e.g., "second", "minute", "hour", "day", 
etc.).
+        relative_start (datetime | None): Optional user-provided base time.
+
+    Returns:
+        datetime: The base time (`now`, `today`, or user-provided).
+    """
+    if relative_start is not None:
+        return relative_start
+
+    granular_units = {"second", "minute", "hour"}
+    broad_units = {"day", "week", "month", "quarter", "year"}
+
+    if unit.lower() in granular_units:
+        return "now"
+    elif unit.lower() in broad_units:
+        return "today"
+    else:
+        raise ValueError(f"Unknown unit: {unit}")

Review Comment:
   ### Insufficient Error Context <sub>![category Error 
Handling](https://img.shields.io/badge/Error%20Handling-ea580c)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The get_relative_base function's ValueError lacks context about the function 
and input values.
   
   ###### Why this matters
   During debugging, it will be harder to identify where this error originated 
and what the valid input values should have been.
   
   ###### Suggested change ∙ *Feature Preview*
   raise ValueError(f"get_relative_base: Unknown time unit '{unit}'. Expected 
one of {granular_units | broad_units}")
   
   
   </details>
   
   ###### Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help 
Korbit improve your reviews.
   
   
   <!--- korbi internal id:3c7516a5-b888-4604-9dd7-8df632fb29da -->
   



-- 
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]

Reply via email to