17 Aug 2019 13:15:52 UTC
- Distribution: Test-MockTime-DateCalc
- Module version: 7
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (277 / 0 / 0)
- KwaliteeBus factor: 2
- 98.00% Coverage
- License: unknown
- Perl: v5.0.0
- Activity24 month
- Download (30.25KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionKRYDE Kevin Rydeand 1 contributors
- Kevin Ryde
Test::MockTime::DateCalc -- fake time for Date::Calc functions
use Test::MockTime; use Test::MockTime::DateCalc; # before Date::Calc loads # ... use My::Module::Using::Date::Calc;
Test::MockTime::DateCalcarranges for the functions in
Date::Calcto follow the Perl level
time()function (see perlfunc) and in particular any fake date/time set there by
Test::MockTime. The following
Date::Calcfunctions are changed
System_Clock Today Now Today_and_Now This_Year Gmtime Localtime Timezone Time_to_Date
Time_to_Dateare made to default to the Perl-level current
time(). When called with an explicit time argument, they're unchanged.
Test::MockTimeor similar fakery must be loaded first, before anything with a
time()call, which includes
Test::MockTime::DateCalc. This is the same as for any
CORE::GLOBALoverride, see "OVERRIDING CORE FUNCTIONS" in CORE.
Test::MockTime::DateCalcmust be loaded before
Date::Calcis 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,
Test::MockTime::DateCalcdemands it be the one to load
Date::Calcfor the first time. Usually this simply means having
Test::MockTime::DateCalcat 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 as not to accidentally rely on
Test::MockTime::DateCalccan be used with other modules which mangle the Perl-level
timetoo. For example
use Time::Fake; # fakery first use Test::MockTime::DateCalc;
use Time::Mock; # fakery first use Test::MockTime::DateCalc;
Time::Warp(as of version 0.5) only exports a new
time, it's not a core override and so can't be used with
Copyright 2009, 2010, 2011, 2019 Kevin Ryde
Test-MockTime-DateCalc is free software; you can redistribute it and/or modify it under the terms of the GNU 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 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Test-MockTime-DateCalc. If not, see <http://www.gnu.org/licenses/>.
Module Install Instructions
To install Test::MockTime::DateCalc, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Test::MockTime::DateCalc
For more information on module installation, please visit the detailed CPAN module installation guide.