Can a d3.timeFormat instance adopt a new d3.locale without being re-created?
0 reputation · 22 Aug 2020, 08:36 UTC
In d3 v4 and later, d3.timeFormat produces parsers that resolve locale-specific tokens such as %B, %b, %A, and %a using the locale active when the formatter is instantiated. The d3.locale object supplies translated month and day names, and parsing is strict: input strings must match the format pattern exactly.
A documented behavior is that changing d3.locale after a format instance exists does not retroactively update that instance. The existing formatter continues to use its original locale definitions unless the formatter is re-created. This creates uncertainty when applications need to switch languages or regional conventions at runtime without rebuilding every format object.
Can an existing d3.timeFormat parser be re-bound to a new locale without re-instantiation, or is recreation the only supported path? If recreation is required, is there a recommended pattern for managing locale changes across many format instances? How does this behavior differ between d3 v4 and later d3 versions?