From: Chris W. <la...@us...> - 2005-02-26 05:56:31
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29627/OpenInteract2 Modified Files: Action.pm Util.pm Log Message: OIN-91: move time spec parsing (simple) from OI2::Action to OI2::Util so we can use it when parsing the user expiration time Index: Action.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Action.pm,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** Action.pm 25 Feb 2005 00:02:22 -0000 1.68 --- Action.pm 26 Feb 2005 05:56:20 -0000 1.69 *************** *** 595,604 **** foreach my $task ( keys %{ $cache_info } ) { my $time_spec = $cache_info->{ $task }; ! $new_info{ $task } = $self->_translate_cache_time( $time_spec ); } $self->{cache_expire} = \%new_info; } elsif ( $cache_info ) { ! my $cache_time = $self->_translate_cache_time( $cache_info ); $self->{cache_expire} = { CACHE_ALL_KEY() => $cache_time }; } --- 595,606 ---- foreach my $task ( keys %{ $cache_info } ) { my $time_spec = $cache_info->{ $task }; ! $new_info{ $task } = OpenInteract2::Util ! ->time_duration_as_seconds( $time_spec ); } $self->{cache_expire} = \%new_info; } elsif ( $cache_info ) { ! my $cache_time = OpenInteract2::Util ! ->time_duration_as_seconds( $cache_info ); $self->{cache_expire} = { CACHE_ALL_KEY() => $cache_time }; } *************** *** 612,629 **** } - sub _translate_cache_time { - my ( $self, $cache_time ) = @_; - return undef unless ( $cache_time ); - my $cache_secs = $cache_time; - if ( $cache_time =~ /^\s*(\d+)(\w)\s*$/ ) { - my $time = $1; - my $spec = lc $2; - $cache_secs = $time * 60 if ( $spec eq 'm' ); - $cache_secs = $time * 3600 if ( $spec eq 'h' ); - $cache_secs = $time * 86400 if ( $spec eq 'd' ); - } - return $cache_secs; - } - # Since we can't be sure what's affected by a change that would prompt # this call, just clear out all cache entries for this action. (For --- 614,617 ---- Index: Util.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Util.pm,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Util.pm 13 Feb 2005 20:22:52 -0000 1.20 --- Util.pm 26 Feb 2005 05:56:20 -0000 1.21 *************** *** 55,59 **** --- 55,76 ---- } + # evaluate a given time specification as number of seconds + sub time_duration_as_seconds { + my ( $class, $time_spec ) = @_; + return undef unless ( defined $time_spec and $time_spec !~ /^\s*$/ ); + # default: spec is just number of seconds + my $secs = $time_spec; + + if ( $time_spec =~ /^\s*(\d+)(\w)\s*$/ ) { + my $time = $1; + my $spec = lc $2; + $secs = $time * 60 if ( $spec eq 'm' ); + $secs = $time * 3600 if ( $spec eq 'h' ); + $secs = $time * 86400 if ( $spec eq 'd' ); + } + return $secs; + + } ######################################## *************** *** 432,435 **** --- 449,472 ---- '2003-04-01' for April 1, 2003. + B<time_duration_in_seconds( $time_spec )> + + Evaluates simple specifications like '3h' or '391m' into seconds. It + does not handle complex ones like '3d5h'. + + Available specs: m (minutes); h (hours); d (days) + + Returns: number of equivalent seconds; + + Example: + + OpenInteract2::Util->time_duration_in_seconds( '5m' ); + # returns: 300 + + OpenInteract2::Util->time_duration_in_seconds( '5h' ); + # returns: 18000 + + OpenInteract2::Util->time_duration_in_seconds( '2d' ); + # returns: 172800 + =head1 FILE METHODS |