@@ -193,7 +193,7 @@ sub offset_for_datetime {
193193sub offset_for_local_datetime {
194194 my $self = shift ;
195195
196- my $span = $self -> _span_for_datetime( ' local' , $_ [0] );
196+ my $span = $self -> _span_for_datetime( ' local' , $_ [0], $_ [1] );
197197
198198 return $span -> [OFFSET];
199199}
@@ -210,6 +210,7 @@ sub _span_for_datetime {
210210 my $self = shift ;
211211 my $type = shift ;
212212 my $dt = shift ;
213+ my $ignore_missing_spans = shift ;
213214
214215 my $method = $type . ' _rd_as_seconds' ;
215216
@@ -218,7 +219,7 @@ sub _span_for_datetime {
218219 my $span ;
219220 my $seconds = $dt -> $method ();
220221 if ( $seconds < $self -> max_span-> [$end ] ) {
221- $span = $self -> _spans_binary_search( $type , $seconds );
222+ $span = $self -> _spans_binary_search( $type , $seconds , $ignore_missing_spans );
222223 }
223224 else {
224225 my $until_year = $dt -> utc_year + 1;
@@ -244,7 +245,7 @@ sub _span_for_datetime {
244245
245246sub _spans_binary_search {
246247 my $self = shift ;
247- my ( $type , $seconds ) = @_ ;
248+ my ( $type , $seconds , $ignore_missing_spans ) = @_ ;
248249
249250 my ( $start , $end ) = _keys_for_type($type );
250251
@@ -276,7 +277,15 @@ sub _spans_binary_search {
276277
277278 $i += $c ;
278279
279- return if $i >= $max ;
280+ if ($i >= $max ) {
281+ # No span found for this time zone? If the user has asked,
282+ # return the previous span so the offset to utc is higher,
283+ # effectively moving the time forward whatever the difference
284+ # in the two spans is (typically 1 hour for DST).
285+ return $self -> {spans }[ $i - 1 ] if $ignore_missing_spans ;
286+
287+ return ;
288+ }
280289 }
281290 else {
282291
@@ -687,14 +696,18 @@ for the given datetime. This takes into account historical time zone
687696information, as well as Daylight Saving Time. The offset is
688697determined by looking at the object's UTC Rata Die days and seconds.
689698
690- =head2 $tz->offset_for_local_datetime( $dt )
699+ =head2 $tz->offset_for_local_datetime( $dt, [ $ignore_missing_spans ] )
691700
692701Given a C<DateTime > object, this method returns the offset in seconds
693702for the given datetime. Unlike the previous method, this method uses
694703the local time's Rata Die days and seconds. This should only be done
695704when the corresponding UTC time is not yet known, because local times
696705can be ambiguous due to Daylight Saving Time rules.
697706
707+ If C<$ignore_missing_spans > is true and the local time for C<$dt > does not
708+ exist in the time zone (due to DST changes for example), the next span
709+ up will be returned.
710+
698711=head2 $tz->is_dst_for_datetime( $dt )
699712
700713Given a C<DateTime > object, this method returns true if the DateTime is
0 commit comments