fn offset_from_local_datetime(&self, local: &NaiveDateTime) -> LocalResult<Self::Offset> {
        let timestamp = local.timestamp();
        let timespans = self.timespans();
        let index = binary_search(0, timespans.len(), |i| timespans.local_span(i).cmp(timestamp));
        TzOffset::map_localresult(
            *self,
            match index {
                Ok(0) if timespans.len() == 1 => LocalResult::Single(timespans.get(0)),
                Ok(0) if timespans.local_span(1).contains(timestamp) => {
                    LocalResult::Ambiguous(timespans.get(0), timespans.get(1))
                }
                Ok(0) => LocalResult::Single(timespans.get(0)),
                Ok(i) if timespans.local_span(i - 1).contains(timestamp) => {
                    LocalResult::Ambiguous(timespans.get(i - 1), timespans.get(i))
                }
                Ok(i) if i == timespans.len() - 1 => LocalResult::Single(timespans.get(i)),
                Ok(i) if timespans.local_span(i + 1).contains(timestamp) => {
                    LocalResult::Ambiguous(timespans.get(i), timespans.get(i + 1))
                }
                Ok(i) => LocalResult::Single(timespans.get(i)),
                Err(_) => LocalResult::None,
            },
        )
    }
// First search for a timespan that the local datetime falls into, then, if it exists,
// check the two surrounding timespans (if they exist) to see if there is any ambiguity.
First search for a timespan that the local datetime falls into, then, if it exists,
check the two surrounding timespans (if they exist) to see if there is any ambiguity.
First search for a timespan that the local datetime falls into then if it exists check the two surrounding timespans ( if they exist ) to see if there is any ambiguity .
fn offset_from_local_datetime(&self, local: &NaiveDateTime) -> LocalResult<Self::Offset> {
        let timestamp = local.timestamp();
        let timespans = self.timespans();
        let index = binary_search(0, timespans.len(), |i| timespans.local_span(i).cmp(timestamp));
        TzOffset::map_localresult(
            *self,
            match index {
                Ok(0) if timespans.len() == 1 => LocalResult::Single(timespans.get(0)),
                Ok(0) if timespans.local_span(1).contains(timestamp) => {
                    LocalResult::Ambiguous(timespans.get(0), timespans.get(1))
                }
                Ok(0) => LocalResult::Single(timespans.get(0)),
                Ok(i) if timespans.local_span(i - 1).contains(timestamp) => {
                    LocalResult::Ambiguous(timespans.get(i - 1), timespans.get(i))
                }
                Ok(i) if i == timespans.len() - 1 => LocalResult::Single(timespans.get(i)),
                Ok(i) if timespans.local_span(i + 1).contains(timestamp) => {
                    LocalResult::Ambiguous(timespans.get(i), timespans.get(i + 1))
                }
                Ok(i) => LocalResult::Single(timespans.get(i)),
                Err(_) => LocalResult::None,
            },
        )
    }
fn offset_from_local_datetime ( & self , local : & NaiveDateTime ) -> LocalResult < Self :: Offset > { let timestamp = local . timestamp ( ) ; let timespans = self . timespans ( ) ; let index = binary_search ( 0 , timespans . len ( ) , | i | timespans . local_span ( i ) . cmp ( timestamp ) ) ; TzOffset :: map_localresult ( * self , match index { Ok ( 0 ) if timespans . len ( ) == 1 => LocalResult :: Single ( timespans . get ( 0 ) ) , Ok ( 0 ) if timespans . local_span ( 1 ) . contains ( timestamp ) => { LocalResult :: Ambiguous ( timespans . get ( 0 ) , timespans . get ( 1 ) ) } Ok ( 0 ) => LocalResult :: Single ( timespans . get ( 0 ) ) , Ok ( i ) if timespans . local_span ( i - 1 ) . contains ( timestamp ) => { LocalResult :: Ambiguous ( timespans . get ( i - 1 ) , timespans . get ( i ) ) } Ok ( i ) if i == timespans . len ( ) - 1 => LocalResult :: Single ( timespans . get ( i ) ) , Ok ( i ) if timespans . local_span ( i + 1 ) . contains ( timestamp ) => { LocalResult :: Ambiguous ( timespans . get ( i ) , timespans . get ( i + 1 ) ) } Ok ( i ) => LocalResult :: Single ( timespans . get ( i ) ) , Err ( _ ) => LocalResult :: None , } , ) }
First search for a timespan that the local datetime falls into, then, if it exists,
check the two surrounding timespans (if they exist) to see if there is any ambiguity.
First search for a timespan that the local datetime falls into then if it exists check the two surrounding timespans ( if they exist ) to see if there is any ambiguity .
&self
local
&NaiveDateTime
&self
local
&NaiveDateTime