Skip to content

Update the TimeZoneProvider trait #409

@nekevss

Description

@nekevss

This issue is meant more for a general discussion for what the trait should look like.

Current

pub trait TimeZoneProvider {
    fn check_identifier(&self, identifier: &str) -> bool;

    fn get_named_tz_epoch_nanoseconds(
        &self,
        identifier: &str,
        local_datetime: IsoDateTime,
    ) -> TemporalResult<Vec<EpochNanoseconds>>;

    fn get_named_tz_offset_nanoseconds(
        &self,
        identifier: &str,
        epoch_nanoseconds: i128,
    ) -> TemporalResult<TimeZoneTransitionInfo>;

    // TODO: implement and stabalize
    fn get_named_tz_transition(
        &self,
        identifier: &str,
        epoch_nanoseconds: i128,
        direction: TransitionDirection,
    ) -> TemporalResult<Option<EpochNanoseconds>>;
}

There are a couple questions here.

  1. This doesn't allow for normalizing and fetching a time zone index, which would allow TimeZone to be Copy.
  2. It's not clear that a request would require epoch_nanoseconds as all time zone database calculations happen in seconds.

Below is some quick general thoughts on changes that could be made to address the first problem.

pub trait TimeZoneProvider {
    type Index: Clone + Copy + Debug;

    fn is_available_name(s: &str) -> Option<Self::Index>;

    fn get_identifier(index: Self::Index) -> &str;

    // other methods
}

The idea here would be to allow the index to be flexible for others usages. Although, I'd also be fine with it being a more straightforward struct like IdentifierIndex(usize) for example.

As for the second, I would propose moving the TimeZoneProvider trait away from nanoseconds in favor of seconds represented by an i64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    providersRelated to time zone providers

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions