App-BorgRestore

 view release on metacpan or  search on metacpan

lib/App/BorgRestore.pm  view on Meta::CPAN


		my %factors = (
			s       => 1,
			second  => 1,
			seconds => 1,
			minute  => 60,
			minutes => 60,
			h       => 60*60,
			hour    => 60*60,
			hours   => 60*60,
			d       => 60*60*24,
			day     => 60*60*24,
			days    => 60*60*24,
			m       => 60*60*24*31,
			month   => 60*60*24*31,
			months  => 60*60*24*31,
			y       => 60*60*24*365,
			year    => 60*60*24*365,
			years   => 60*60*24*365,
		);

		if (exists($factors{$unit})) {
			return $value * $factors{$unit};
		}
	}

	return;
}

t/timespec_to_seconds.t  view on Meta::CPAN


use Log::Any::Adapter ('TAP');
use Test::More;

use App::BorgRestore;

my $app = App::BorgRestore->new_no_defaults(undef);

is($app->_timespec_to_seconds('5s'), 5, '5 seconds');
is($app->_timespec_to_seconds('5minutes'), 5*60, '5 minutes');
is($app->_timespec_to_seconds('6d'), 6*60*60*24, '6 days');
is($app->_timespec_to_seconds('8m'), 8*60*60*24*31, '8 months');
is($app->_timespec_to_seconds('2y'), 2*60*60*24*365, '2 years');

is($app->_timespec_to_seconds('5sec'), undef, 'invalid unit returns undef');
is($app->_timespec_to_seconds('5'), undef, 'missing unit returns undef');
is($app->_timespec_to_seconds('blub'), undef, 'string returns undef');
is($app->_timespec_to_seconds(''), undef, 'empty string returns undef');

done_testing;



( run in 0.350 second using v1.01-cache-2.11-cpan-7add2cbd662 )