Skip to content

Filtering by regex for a single zone includes many zones #215

@robertbastian

Description

@robertbastian

If I set the filter to Europe/Zurich, I expect only that zone to be included. However, all of these zones are included:

pub static TZ_VARIANTS: [Tz; 47] = [
    Tz::Etc__GMT,
    Tz::Etc__GMTPlus0,
    Tz::Etc__GMTPlus1,
    Tz::Etc__GMTPlus10,
    Tz::Etc__GMTPlus11,
    Tz::Etc__GMTPlus12,
    Tz::Etc__GMTPlus2,
    Tz::Etc__GMTPlus3,
    Tz::Etc__GMTPlus4,
    Tz::Etc__GMTPlus5,
    Tz::Etc__GMTPlus6,
    Tz::Etc__GMTPlus7,
    Tz::Etc__GMTPlus8,
    Tz::Etc__GMTPlus9,
    Tz::Etc__GMTMinus0,
    Tz::Etc__GMTMinus1,
    Tz::Etc__GMTMinus10,
    Tz::Etc__GMTMinus11,
    Tz::Etc__GMTMinus12,
    Tz::Etc__GMTMinus13,
    Tz::Etc__GMTMinus14,
    Tz::Etc__GMTMinus2,
    Tz::Etc__GMTMinus3,
    Tz::Etc__GMTMinus4,
    Tz::Etc__GMTMinus5,
    Tz::Etc__GMTMinus6,
    Tz::Etc__GMTMinus7,
    Tz::Etc__GMTMinus8,
    Tz::Etc__GMTMinus9,
    Tz::Etc__GMT0,
    Tz::Etc__Greenwich,
    Tz::Etc__UCT,
    Tz::Etc__UTC,
    Tz::Etc__Universal,
    Tz::Etc__Zulu,
    Tz::Europe__Busingen,
    Tz::Europe__Vaduz,
    Tz::Europe__Zurich,
    Tz::GMT,
    Tz::GMTPlus0,
    Tz::GMTMinus0,
    Tz::GMT0,
    Tz::Greenwich,
    Tz::UCT,
    Tz::UTC,
    Tz::Universal,
    Tz::Zulu,
];

UTC and all GMT+- zones are included in spite of the filter, and all zones that link to to any of them are also included.

Including all these zones increases the size of DateTime<Tz> by 8 bytes (including only a second zone does this, due to Tz becoming non-zero-sized). It also adds data for display names, and blocks optimisations (if Tz has a single variant, the compiler can inline more things because there's no branching).

UTC is included because the crate wouldn't build otherwise, GMT seems to have been included because it's "generally expected to always exist", and the GMT+- zones are probably included by accident because they match the GMT pattern.

I think all of them should be removed. If you need to do UTC logic, you don't need chrono_tz, you can use chrono::UTC (that type is better for interop anyway). Similarly, there's chrono::FixedOffset for the other zones. The only feature difference is that you can parse the chrono_tz types and get display names for them, however if you want that you should include them in the regex explicitly, because that increases binary size.

This leaves the issue of the Default impl for Tz, which I think should be removed altogether. It's a bit of a footgun because it allows you to create DateTimes without thinking about time zones. Just write Tz::UTC explicitly if you need UTC.

Incoming aliases should also be removed. I think they are currently included due to the way the filtering is done on the Table level, where Europe/Zurich needs to be kept if the regex is Europe/Vaduz. The filtering needs to be moved to the loops that write the zones, which is trivial for timezones.rs but more complicated for directory.rs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions