codeant-ai-for-open-source[bot] commented on code in PR #41727:
URL: https://github.com/apache/superset/pull/41727#discussion_r3517896073


##########
superset-frontend/plugins/legacy-preset-chart-nvd3/src/TimePivot/transformData.ts:
##########
@@ -0,0 +1,164 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { DTTM_ALIAS } from '@superset-ui/core';
+
+const DAY_MS = 24 * 60 * 60 * 1000;
+const WEEKDAYS = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'];
+
+/**
+ * Rolls a timestamp back to the start of its period the way pandas
+ * offset.rollback(normalize=True) does for the offset aliases the
+ * frequency control offers (AS/A, MS/M, W and W-XXX, D, H, T/MIN).
+ * The multiplier prefix (e.g. 52W-MON) does not change the anchor.
+ */
+export const rollback = (timestamp: number, freq: string): number => {
+  const match = /^\d*(AS|YS|A|Y|MS|M|W(?:-([A-Z]{3}))?|D|H|T|MIN)$/i.exec(
+    (freq || 'W-MON').trim(),
+  );
+  const date = new Date(timestamp);
+  const midnight = Date.UTC(
+    date.getUTCFullYear(),
+    date.getUTCMonth(),
+    date.getUTCDate(),
+  );
+  if (!match) {
+    return midnight; // freeform rules fall back to day boundaries
+  }

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag the TimePivot frequency parser for lacking support for 
exotic/unsupported pandas aliases; the chart only exposes the six supported 
dropdown choices, and falling back to day boundaries for unexpressible rollback 
semantics is intentional.
   
   **Applied to:**
     - `superset-frontend/plugins/legacy-preset-chart-nvd3/src/TimePivot/**`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



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