Hello All,

For some reason using DateTime->now doesn't get effected by using the
Test::MockTime module to change the time. The Test module overrides
the time builtin, which seems to be what DateTime::now is using.

 #!/usr/bin/perl
 use DateTime;
 use Test::MockTime qw/:all/;

 my $start_time = time;
 print "T: $start_time\n",
 "DT:".DateTime->now()."\n";
 print "----\n";
 set_relative_time(6000);
 my $rel_time = time;
 print "T: $rel_time diff:".($rel_time-$start_time)."\n",
 "DT:".DateTime->now()."\n";

 $ perl test-mocktime.pl
 T: 1219910364
 DT:2008-08-28T07:59:24
 ----
 T: 1219916364 diff:6000
 DT:2008-08-28T07:59:24

After hours fiddling around in the debugger I can't see what is going
on. Calling time in the DateTime package returns the mocked time but
DateTime::now only sees the real time. Calling as 'scalar time' like
the method makes no difference either.

475:    sub now { shift->from_epoch( epoch => (scalar time), @_ ) }

Ideas anyone? Debug output below in case it helps.

cheers,
mark
--
"In the beginning, there was nothing, which exploded."


---- DEBUG -----
main::(test-mocktime.pl:10):    set_relative_time(6000);


                    DB<6> p time
1219912180


                    DB<7> n
main::(test-mocktime.pl:11):    my $rel_time = time;


                    DB<7> p time
1219918183


                    DB<8> c
DateTime::now(/usr/local/lib/perl/5.8.8/DateTime.pm:475):
475:    sub now { shift->from_epoch( epoch => (scalar time), @_ ) }


                    DB<8> p time
1219918188


                    DB<9> s
DateTime::from_epoch(/usr/local/lib/perl/5.8.8/DateTime.pm:449):
449:            my $class = shift;


                    DB<9> x @_
0  'DateTime'
1  'epoch'
2  1219912189


                    DB<10> p time
1219918193

Reply via email to