SYNOPSIS

 use Test::MockTime;
 use Test::MockTime::DateCalc; # before Date::Calc loads
 # ...
 use My::Module::Using::Date::Calc;

DESCRIPTION

\*(C`Test::MockTime::DateCalc\*(C' arranges for the functions in \*(C`Date::Calc\*(C' to follow the Perl level \*(C`time\*(C' function (see perlfunc), and in particular any fake date/time set there by \*(C`Test::MockTime\*(C'. The following \*(C`Date::Calc\*(C' functions are changed

System_Clock Today Now Today_and_Now This_Year

Gmtime Localtime Timezone Time_to_Date

\*(C`Gmtime\*(C', \*(C`Localtime\*(C', \*(C`Timezone\*(C' and \*(C`Time_to_Date\*(C' are made to default to the Perl-level current \*(C`time\*(C'. When called with an explicit time argument they're unchanged.

Module Load Order

\*(C`Test::MockTime\*(C' or similar fakery must be loaded first, before anything with a \*(C`time()\*(C' call, which includes \*(C`Test::MockTime::DateCalc\*(C'. This is the same as all \*(C`CORE::GLOBAL\*(C' overrides, see \*(L"\s-1OVERRIDING\s0 \s-1CORE\s0 \s-1FUNCTIONS\s0\*(R" in \s-1CORE\s0.

\*(C`Test::MockTime::DateCalc\*(C' must be loaded before \*(C`Date::Calc\*(C'. If \*(C`Date::Calc\*(C' is already loaded then its functions might have been imported into other modules and such imports are not affected by the redefinitions made. For that reason \*(C`Test::MockTime::DateCalc\*(C' demands it be the one to load \*(C`Date::Calc\*(C' for the first time. Usually this simply means having \*(C`Test::MockTime::DateCalc\*(C' at the start of a test script, before the things you're going to test.

use strict; use warnings; use Test::MockTime ':all'; use Test::MockTime::DateCalc;

use My::Foo::Bar;

set_fixed_time('1981-01-01T00:00:00Z'); is (My::Foo::Bar::something(), 1981); restore_time();

In a test script it's often good to have your own modules early to check they correctly load their pre-requisites. You might want a separate test script for that so you don't accidentally rely on \*(C`Test::MockTime::DateCalc\*(C' loading \*(C`Date::Calc\*(C' for you.

Other Faking Modules

\*(C`Test::MockTime::DateCalc\*(C' can be used with other modules which mangle the Perl-level \*(C`time\*(C' too. For example \*(C`Time::Fake\*(C',

use Time::Fake; # fakery first use Test::MockTime::DateCalc;

Or \*(C`Time::Mock\*(C',

use Time::Mock; # fakery first use Test::MockTime::DateCalc;

\*(C`Time::Warp\*(C' (as of version 0.5) only exports a new \*(C`time\*(C', it's not a core override and so can't be used with \*(C`Test::MockTime::DateCalc\*(C'.

RELATED TO Test::MockTime::DateCalc…

Date::Calc, Test::MockTime, Time::Fake, Time::Mock

faketime\|(1)

HOME PAGE

http://user42.tuxfamily.org/test-mocktime-datecalc/index.html

COPYRIGHT

Copyright 2009, 2010 Kevin Ryde

Test-MockTime-DateCalc is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Test-MockTime-DateCalc is distributed in the hope that it will be useful, but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of \s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0. See the \s-1GNU\s0 General Public License for more details.

You should have received a copy of the \s-1GNU\s0 General Public License along with Test-MockTime-DateCalc. If not, see <http://www.gnu.org/licenses/>.