Skip to content

Instantly share code, notes, and snippets.

@cho45
Forked from motemen/gist:325058
Created Apr 3, 2010
Embed
What would you like to do?
use strict;
use warnings;
use Test::More;
use DateTime;
my $dt1 = DateTime->now;
{
t::Util::timeshift(seconds => 10);
my $dt2 = DateTime->now;
cmp_ok $dt2->epoch - $dt1->epoch, '>=', 10;
}
my $dt3 = DateTime->now;
cmp_ok $dt3->epoch - $dt1->epoch, '<=', 10;
done_testing;
package t::Util;
use strict;
use warnings;
use Scope::Upper qw(localize UP);
sub timeshift (%) {
my %opts = @_;
my $ORIGINAL_now = \&DateTime::now;
localize '&DateTime::now' => sub {
my (@args) = @_;
$ORIGINAL_now->(@args)->add(%opts);
}, UP;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment