1package main; 2 3use strict; 4use warnings; 5 6use lib qw{ inc }; 7 8use Test::More 0.88; 9use My::Module::Test::App; 10 11BEGIN { 12 13 eval { 14 15 no warnings qw{ once }; 16 # Force Date::Manip 5 backend if we have Date::Manip 6. 17 local $Date::Manip::Backend = 'DM5'; 18 19 require Date::Manip; 20 21 1; 22 } or plan skip_all => 'Date::Manip not available'; 23 24 $^O eq 'MSWin32' 25 and plan skip_all => 'Date::Manip 5 tests fail under Windows'; 26 27 require Astro::Coord::ECI::Utils; 28 Astro::Coord::ECI::Utils->VERSION( '0.112' ); 29 Astro::Coord::ECI::Utils->import( qw{ greg_time_gm greg_time_local } ); 30 31} 32 33dump_date_manip_init(); 34 35# The following is a hook for the author test that forces this to run 36# under Date::Manip 5.54. We want the author test to fail if we get 37# version 6. 38 39our $DATE_MANIP_5_REALLY; 40 41if ( $DATE_MANIP_5_REALLY ) { 42 ( my $ver = Date::Manip->VERSION() ) =~ s/ _ //smxg; 43 cmp_ok $ver, '<', 6, 'Date::Manip version is really less than 6'; 44} 45 46require_ok 'Astro::App::Satpass2::ParseTime'; 47 48klass( 'Astro::App::Satpass2::ParseTime' ); 49 50call_m( new => class => 'Astro::App::Satpass2::ParseTime::Date::Manip', 51 INSTANTIATE, 'Instantiate' ); 52 53call_m( isa => 'Astro::App::Satpass2::ParseTime::Date::Manip::v5', TRUE, 54 'Object is an Astro::App::Satpass2::ParseTime::Date::Manip::v5' ); 55 56call_m( isa => 'Astro::App::Satpass2::ParseTime', TRUE, 57 'Object is an Astro::App::Satpass2::ParseTime' ); 58 59call_m( 'delegate', 60 'Astro::App::Satpass2::ParseTime::Date::Manip::v5', 61 'Delegate is Astro::App::Satpass2::ParseTime::Date::Manip::v5' ); 62 63call_m( use_perltime => TRUE, 'Uses perltime' ); 64 65call_m( parse => '20100202T120000Z', 66 greg_time_gm( 0, 0, 12, 2, 1, 2010 ), 67 'Parse noon on Groundhog Day 2010' ); 68 69my $base = greg_time_gm( 0, 0, 0, 1, 3, 2009 ); # April 1, 2009 GMT; 70use constant ONE_DAY => 86400; # One day, in seconds. 71use constant HALF_DAY => 43200; # 12 hours, in seconds. 72 73call_m( base => $base, TRUE, 'Set base time to 01-Apr-2009 GMT' ); 74 75call_m( parse => '+0', $base, 'Parse of +0 returns base time' ); 76 77call_m( parse => '+1', $base + ONE_DAY, 78 'Parse of +1 returns one day later than base time' ); 79 80call_m( parse => '+0', $base + ONE_DAY, 81 'Parse of +0 now returns one day later than base time' ); 82 83call_m( 'reset', TRUE, 'Reset to base time' ); 84 85call_m( parse => '+0', $base, 'Parse of +0 returns base time again' ); 86 87call_m( parse => '+0 12', $base + HALF_DAY, 88 q{Parse of '+0 12' returns base time plus 12 hours} ); 89 90call_m( 'reset', TRUE, 'Reset to base time again' ); 91 92call_m( parse => '-0', $base, 'Parse of -0 returns base time' ); 93 94call_m( parse => '-0 12', $base - HALF_DAY, 95 'Parse of \'-0 12\' returns 12 hours before base time' ); 96 97call_m( perltime => 1, TRUE, 'Set perltime true' ); 98 99SKIP: { 100 101 Time::y2038->can( 'timegm' ) 102 and skip 'Time::y2038 has problems with summer/winter time', 2; 103 104 call_m( parse => '20090101T000000', 105 greg_time_local( 0, 0, 0, 1, 0, 2009 ), 106 'Parse ISO-8601 20090101T000000' ) 107 or dump_date_manip(); 108 109 call_m( parse => '20090701T000000', 110 greg_time_local( 0, 0, 0, 1, 6, 2009 ), 111 'Parse ISO-8601 20090701T000000' ) 112 or dump_date_manip(); 113 114} 115 116call_m( perltime => 0, TRUE, 'Set perltime false' ); 117 118my $time_gm = greg_time_gm( 0, 0, 0, 1, 0, 2009 ); 119call_m( parse => '20090101T000000Z', 120 $time_gm, 121 'Parse ISO-8601 20090101T000000Z' ) 122 or dump_date_manip( $time_gm ); 123 124$time_gm = greg_time_gm( 0, 0, 0, 1, 6, 2009 ); 125call_m( parse => '20090701T000000Z', 126 $time_gm, 127 'Parse ISO-8601 20090701T000000Z' ) 128 or dump_date_manip( $time_gm ); 129 130done_testing; 131 1321; 133 134# ex: set textwidth=72 : 135