develooper Front page | perl.datetime | Postings from February 2007

"Set::Infinite backtrack too deep" from DateTime::Set

Thread Next
From:
Joshua ben Jore
Date:
February 4, 2007 20:40
Subject:
"Set::Infinite backtrack too deep" from DateTime::Set
Message ID:
dc5c751d0702042039x3c5e37efwd8246ea491ce438@mail.gmail.com
I'm using DateTime::Set to encode a radio station's program lineup.
It's about 170 weekly recurrences that are all mostly about an hour
apart. If I try to find the current event it's really slow and I get a
pile of warnings from Set::Infinite. I can get the warnings to go away
if I set $Set::Infinite::max_backtrack_depth to 52. I can get
semi-reasonable performance for the ->current call if I restrict the
set being queried to only the recent past.

The warning:
  Set::Infinite: Backtrack too deep (more than 10 levels) at
/home/josh/bin/perl/5.8.8/lib/site_perl/5.8.8/DateTime/Set.pm line 535

I'm hoping someone here can suggest a better way to do this, get
better performance from the ->current query, avoid having to manually
guess the range I'll find an answer in, and what's the deal with the
warnings.

  # Look up whatever is current for a date/time.
  $THE_DATE = ...

  $all_events = DateTime::Set->empty_set->set_time_zone( 'US/Central' )
  for ( ... )
      $all_events = $all_events->union(
          DateTime::Event::Recurrence
              ->weekly( %$_ )
              ->set_time_zone( 'US/Central' )
      )

  local $Set::Infinite::max_backtrack_depth = 52 # Set::Infinite, shut up!

  # Restrict $all_events to only the recent past because this makes
the query faster
  $recent_past = $all_events->intersection(
      DateTime::Span->from_datetimes(
          from => $THE_DATE->clone->subtract( hours => 4 )->truncate(
to => 'hour' ),
          end => $THE_DATE
      )
  )

  $CURRENT = $recent_past->current( $THE_DATE )

Josh

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About