Skip to content

Instantly share code, notes, and snippets.

@motemen
Created March 8, 2010 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save motemen/325058 to your computer and use it in GitHub Desktop.
Save motemen/325058 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Test::More;
use DateTime;
my $dt1 = DateTime->now;
{
t::Util::timeshift(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 $n = shift;
my $now = DateTime->now;
localize '&DateTime::now' => sub {
$now->add(seconds => $n);
}, UP;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment