I recently had to test my model which has a method which depends on DateTime->now. The problem with testing is, that the returned value will change depending on the current time.
I could have copied the logic from the model’s method but that would have made the test obsolete. Instead I choose to mock the current time and looked for a proper module on CPAN. And was lucky: Test::MockTime does just what I want:
use Test::MockTime qw(set_absolute_time); set_absolute_time('2009-04-24T00:00:00Z');
And that’s it!
But make shure you load modules like DateTime after Test::MockTime!