BioGeek has asked for the wisdom of the Perl Monks concerning the following question:

I'm currently reading Test::Tutorial, and following along with the exercises as they are presented. From the part 'Test the manual' I litterally copy/pasted the following code:
#!/usr/bin/perl -w + use Test::More tests => 8; + use Date::ICal; + $ical = Date::ICal->new( year => 1964, month => 10, day => 16, hour => 16, min => 12, sec => 47, tz => '0530' ); + ok( defined $ical, 'new() returned something' ); ok( $ical->isa('Date::ICal'), " and it's the right class" ); is( $ical->sec, 47, ' sec()' ); is( $ical->min, 12, ' min()' ); is( $ical->hour, 16, ' hour()' ); is( $ical->day, 17, ' day()' ); is( $ical->month, 10, ' month()' ); is( $ical->year, 1964, ' year()' );
but instead of the result in the tutorial I get:
1..8 ok 1 - new() returned something ok 2 - and it's the right class ok 3 - sec() ok 4 - min() not ok 5 - hour() # Failed test (testtut7.pl at line 15) # got: '14' # expected: '16' not ok 6 - day() # Failed test (testtut7.pl at line 16) # got: '16' # expected: '17' ok 7 - month() ok 8 - year() # Looks like you failed 2 tests of 8.
I agree with the failure for test 6, that's correct as further described in the tutorial. But I honestly cannot see why test 5 also fails. The number 14 is nowhere to be seen in the program!

I triple-checked everyrhing, searched explicitly for the number 14 in the file testtut7.pl, copy/pasted the code snippet again from the tutorial in a new file; but the problem remains. I'm stumped now.

Replies are listed 'Best First'.
Re: Strange result for example in Test::Tutorial.
by moot (Chaplain) on Apr 13, 2005 at 03:39 UTC
    I think you're bumping up against a timezone conversion. Seems that 1.72 at least of Date::ICal uses 'offset', not 'tz' to set the timezone, so it is using $TZ by default.
      replacing the string tz => '0530' with eg. offset => '-0800' indeed solves the problem.

      So, what to do best now? Contact the author/maintainer of Test::Tutorial to update the tutorial?
        It couldn't hurt, although it does seem like an odd test case anyway, since it is dependent on an external (to T::Tutorial) module's API.