SEPURI-SAI-KRISHNA commented on code in PR #45410:
URL: https://github.com/apache/superset/pull/45410#discussion_r4356554018


##########
superset/charts/client_processing.py:
##########
@@ -835,6 +863,45 @@ def union_currency_context(
 }
 
 
+def is_strftime_expressible(d3_time_format: str) -> bool:
+    """Whether every directive in a d3 time format means the same to 
strftime."""
+    if LOCAL_TIME_PREFIX in d3_time_format:
+        # ``TimeFormatterRegistry.get`` strips the marker before building the
+        # formatter, so leaving it in would render it as literal text.
+        return False
+    directives = re.findall(r"%(.)", d3_time_format)

Review Comment:
   Confirmed against d3. `utcFormat` on 2021-01-01 13:05:09 UTC:
   
   ```
   format        d3            strftime
   %Y%           2021          2021%
   %d/%m/%Y%     01/01/2021    01/01/2021%
   %%%           %             %%
   %Y%%%         2021%         2021%%
   ```
   
   So a `%` that no directive consumes has to make the format non-expressible. 
`%%` is not that case, both read it as one escaped `%` and agree, so the 
allowlist keeps `%`.
   
   Added after the no-directive rule so the existing cases keep their path:
   
   ```python
       if "%" in re.sub(r"%.", "", d3_time_format):
           return False
   ```
   
   Stripping every `%` a directive consumes leaves behind exactly the stray 
ones. It rejects all four formats above and accepts `%Y%%`, `100%%` and the 
ordinary ones. Pinned by 
`test_table_skips_a_time_format_with_an_unconsumed_percent` over the four.
   



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