rusackas commented on code in PR #41727:
URL: https://github.com/apache/superset/pull/41727#discussion_r3517893069


##########
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:
   Added QS/Q support (quarter start/end)... anything the parser still can't 
express falls back to day boundaries, which for rollback semantics only matters 
for exotic anchored aliases. The legacy chart shipped six choices in the 
dropdown, all covered.



##########
superset-frontend/plugins/legacy-preset-chart-nvd3/test/TimePivot.test.ts:
##########
@@ -0,0 +1,96 @@
+/**
+ * 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 { QueryFormData } from '@superset-ui/core';
+import buildQuery from '../src/TimePivot/buildQuery';
+import transformData, { rollback } from '../src/TimePivot/transformData';
+
+describe('TimePivot buildQuery', () => {

Review Comment:
   Flattened, thanks.



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