bito-code-review[bot] commented on code in PR #36318:
URL: https://github.com/apache/superset/pull/36318#discussion_r2570607504


##########
superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx:
##########
@@ -298,6 +299,78 @@ function SelectPageSize({
 const getNoResultsMessage = (filter: string) =>
   filter ? t('No matching records found') : t('No records found');
 
+//Calculates the end time based on the granularity
+function getEndTimeFromGranularity(
+  startTime: Date,
+  granularity?: TimeGranularity,
+): Date {
+  if (!granularity) {
+    return startTime;
+  }
+
+  const time = startTime.getTime();
+  const date = startTime.getUTCDate();
+  const month = startTime.getUTCMonth();
+  const year = startTime.getUTCFullYear();
+
+  // Constants for time calculations
+  const MS_IN_SECOND = 1000;
+  const MS_IN_MINUTE = 60 * MS_IN_SECOND;
+  const MS_IN_HOUR = 60 * MS_IN_MINUTE;
+
+  switch (granularity) {
+    case TimeGranularity.SECOND:
+    case 'PT1S':
+      return new Date(time + MS_IN_SECOND);
+    case TimeGranularity.MINUTE:
+    case 'PT1M':
+      return new Date(time + MS_IN_MINUTE);
+    case TimeGranularity.FIVE_MINUTES:
+    case 'PT5M':
+      return new Date(time + MS_IN_MINUTE * 5);
+    case TimeGranularity.TEN_MINUTES:
+    case 'PT10M':
+      return new Date(time + MS_IN_MINUTE * 10);
+    case TimeGranularity.FIFTEEN_MINUTES:
+    case 'PT15M':
+      return new Date(time + MS_IN_MINUTE * 15);
+    case TimeGranularity.THIRTY_MINUTES:
+    case 'PT30M':
+      return new Date(time + MS_IN_MINUTE * 30);
+    case TimeGranularity.HOUR:
+    case 'PT1H':
+      return new Date(time + MS_IN_HOUR);
+    case TimeGranularity.DAY:
+    case TimeGranularity.DATE:
+    case 'P1D':
+    case 'date':
+      return new Date(Date.UTC(year, month, date + 1));
+    case TimeGranularity.WEEK:
+    case TimeGranularity.WEEK_STARTING_SUNDAY:
+    case TimeGranularity.WEEK_STARTING_MONDAY:
+    case 'P1W':
+    case '1969-12-28T00:00:00Z/P1W':
+    case '1969-12-29T00:00:00Z/P1W':
+      return new Date(Date.UTC(year, month, date + 7));
+    case TimeGranularity.WEEK_ENDING_SATURDAY:
+    case TimeGranularity.WEEK_ENDING_SUNDAY:
+    case 'P1W/1970-01-03T00:00:00Z':
+    case 'P1W/1970-01-04T00:00:00Z':
+      return new Date(Date.UTC(year, month, date + 1));
+    case TimeGranularity.MONTH:
+    case 'P1M':
+      return new Date(Date.UTC(year, month + 1, 1));
+    case TimeGranularity.QUARTER:
+    case 'P3M':
+      return new Date(Date.UTC(year, Math.floor(month / 3) * 3 + 3, 1));
+    case TimeGranularity.YEAR:
+    case 'P1Y':
+      return new Date(Date.UTC(year + 1, 0, 1));
+    default:
+      return new Date(Date.UTC(year, month, date + 1));
+  }
+}

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Incorrect time range calculation</b></div>
   <div id="fix">
   
   The getEndTimeFromGranularity function returns the start of the next period 
instead of the end of the current period, causing incorrect time ranges in 
drill-to-detail for temporal columns. For example, for DAY granularity, it 
returns the start of the next day rather than 23:59:59.999 of the current day. 
This matches the `createTimeRangeFromGranularity` utility in @superset-ui/core, 
which handles inclusive ranges properly.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run <a 
href=https://github.com/apache/superset/pull/36318#issuecomment-3588078350>#c735a1</a></i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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