Bug description
The new PR introduced custom D3 datetime formatting.
However, it works partially - when datetime format is forced to %b
, %B
for example.
When the datetime is set to Adaptive
, the custom datetime format ignored reverting back month names to English.
How to reproduce the bug:
Add a custom D3 Time format to superset_config.py
:
D3_TIME_FORMAT = {
"dateTime": "%d.%m.%Y %H:%M:%S",
"date": "%d.%m.%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота", "Воскресенье"],
"shortDays": ["Пон", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"],
"months": ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
"shortMonths": ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"]
}
Create a virtual dataset with some data (PostgreSQL syntax):
select startdate::date as startdate
, floor(random() * 100) + 1 AS random_integer
from generate_series('2024-05-25', now(), '1 day'::interval) as startdate
order by startdate desc;
Create a line chart with start_date
on the X-axis, random_integer
on the Y-axis:
Change X-axis datetime format to %B
, note the changes:
Screenshots/recordings
Another example related to the same behaviour:
The custom D3 datetime format shows up when a certain datetime format applied, for example %B
:
But in case an adaptive
formatting applied on the X axis, the E3 formatting is reverting back to defaults (English):
Superset version
4.1.1
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
Checklist
- [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [X] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Comment From: dosubot[bot]
The issue you're experiencing with the 'adaptive' datetime formatting option reverting to English month names instead of using your custom D3 datetime format is likely due to how the 'adaptive' option is implemented in Superset. The 'adaptive' option, when set, uses a dynamic formatter based on the data's granularity and does not automatically apply custom D3 formats specified in superset_config.py
for localization [1][2].
To address this, you might need to ensure that the locale settings are correctly applied when using the 'adaptive' option. The createSmartDateFormatter
function in the codebase supports a locale
parameter, which can be used to provide non-English month and day names [3]. However, it seems that this locale parameter might not be automatically linked to the custom D3 formats defined in superset_config.py
.
A potential workaround could be to explicitly set the locale in the frontend code where the formatter is applied, ensuring that your custom month and day names are used. This might require modifying the Superset codebase to pass the locale information from your configuration to the formatter.
If this approach is not feasible, consider using a specific D3 format instead of 'adaptive' to ensure your custom settings are applied.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other
Comment From: edogev
Нашли решение по этому вопросу? У меня аналогичная прблемма.
Have you found a solution to this issue? I have a similar problem.
Comment From: ampil
Нашли решение по этому вопросу? У меня аналогичная прблемма.
Have you found a solution to this issue? I have a similar problem.
Nope, I haven't.
Comment From: rusackas
If anyone wants to review/test the linked PR/branch, please do, so we can close out this issue :D