Created
March 8, 2010 10:31
-
-
Save motemen/325058 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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