package TimeOffset;
sub import {
my $pkg = shift;
my $offset = shift || "+0";
if ($offset !~ /^[+-]/) {
$offset = $offset - time;
}
*CORE::GLOBAL::time = sub { CORE::time() + $offset };
*CORE::GLOBAL::localtime = sub {
return @_ ? CORE::localtime(@_)
: CORE::localtime(CORE::time() + $offset);
};
*CORE::GLOBAL::gmtime = sub {
return @_ ? CORE::gmtime(@_)
: CORE::gmtime(CORE::time() + $offset);
};
}
1;
####
use TimeOffset '+3600'; # pretend it's 1hr in the future
##
##
use TimeOffset '-60'; # pretend it's 1min in the past
##
##
use TimeOffset 12345678; # pretend the program was started
# at 12345678 epoch seconds