feat(timezone): runtime-registerable IANA aliases (env var + API)#464
Merged
feat(timezone): runtime-registerable IANA aliases (env var + API)#464
Conversation
Add `register_timezone_alias(name, iana)` and `IBAPI_TIMEZONE_ALIASES` env var so users can map gateway-supplied timezone strings without rebuilding. User entries take precedence over the built-in table. Update the unsupported-timezone error to mention both options so users discover the fix on the first hit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
register_timezone_alias(name, iana)andIBAPI_TIMEZONE_ALIASESenv var so users can map gateway-supplied timezone strings without rebuilding the crate.TIMEZONE_ALIASEStable — works for both new entries and overrides.Why
IB Gateway emits a free-form timezone string from the host OS locale (e.g. China Standard Time, Romance Standard Time, GB2312 mojibake). When the gateway sends a label not in our built-in table, the connection fails. Today the only fix is a new release with the alias added — slow for users and high-touch for maintainers.
Design
static TIMEZONE_REGISTRY: LazyLock<Mutex<HashMap<String, String>>>seeded once from the env var (mirrors the pattern atsrc/stubs.rs:40).TIMEZONE_ALIASES→ mojibake heuristic →time_tzpassthrough.name=iana;name=ianawith whitespace trimmed; malformed entries are warned and skipped (env-var typos should not kill connection setup).debug!line on registry hit so users can verify withRUST_LOG=ibapi::common::timezone=debugthat their alias is firing.Out of scope (follow-up)
src/market_data/historical/common/decoders/mod.rs—parse_time_zonepanics on unknown names. Inherits the registry behavior, but the panic itself is a separate bug worth its own PR.Test plan
cargo +1.93.0 clippy --all-targets -- -D warningscargo +1.93.0 clippy --all-targets --features sync -- -D warningscargo +1.93.0 clippy --all-featurescargo +1.93.0 test --features sync(180 passed)cargo +1.93.0 test --features async(105 passed)register_timezone_aliassmoke path.test_parse_connection_time_unknown_timezone_errorsextended to assert the error message mentionsregister_timezone_aliasandIBAPI_TIMEZONE_ALIASES.