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    # Workaround for bug (well, _I_ think it's a bug) introduced into
14    # Date::Manip with 6.34, while fixing RT #78566. My bug report is RT
15    # #80435.
16    my $path = $ENV{PATH};
17    local $ENV{PATH} = $path;
18
19    eval {
20	# The following localizations are to force the Date::Manip 6
21	# backend
22	local $ENV{DATE_MANIP} = 'DM6';
23	local $Date::Manip::Backend = 'DM6';
24	require Date::Manip;
25	1;
26    } or plan skip_all => 'Date::Manip not available';
27
28    my $ver = Date::Manip->VERSION();
29    Date::Manip->import();
30    ( my $test = $ver ) =~ s/ _ //smxg;
31    $test >= 6
32	or plan skip_all =>
33	    "Date::Manip $ver installed; this test is for 6.00 or greater";
34
35    $] >= 5.010
36	or plan skip_all =>
37	    "Date::Manip version 6 backend not available under Perl $]";
38
39    require Astro::Coord::ECI::Utils;
40    Astro::Coord::ECI::Utils->VERSION( '0.112' );
41    Astro::Coord::ECI::Utils->import( qw{ greg_time_gm greg_time_local } );
42
43    {
44	my ( $dm_zone, $dt_zone );
45	eval {
46	    $dm_zone = Date::Manip::Date_TimeZone();
47	    require DateTime::TimeZone;
48	    $dt_zone = DateTime::TimeZone->new( name => 'local')->name();
49	    1;
50	} and lc $dm_zone ne lc $dt_zone
51	    and plan skip_all =>
52	    "Date::Manip zone is '$dm_zone' but DateTime zone is '$dt_zone'";
53    }
54
55}
56
57dump_date_manip_init();
58my $path = $ENV{PATH};
59
60require_ok 'Astro::App::Satpass2::ParseTime';
61
62note <<'EOD';
63The following test is to make sure we have worked around RT ticket
64#80435: [patch] Date::Manip clobbers $ENV{PATH} on *nix
65EOD
66
67is $ENV{PATH}, $path, 'Ensure that the PATH is prorected at load';
68
69klass( 'Astro::App::Satpass2::ParseTime' );
70
71call_m( new => class => 'Astro::App::Satpass2::ParseTime::Date::Manip',
72    INSTANTIATE, 'Instantiate' );
73
74note <<'EOD';
75The following test is to make sure we have worked around RT ticket
76#80435: [patch] Date::Manip clobbers $ENV{PATH} on *nix
77EOD
78
79is $ENV{PATH}, $path, 'Ensure that the PATH is prorected at instantiation';
80
81call_m( isa => 'Astro::App::Satpass2::ParseTime::Date::Manip::v6', TRUE,
82    'Object is an Astro::App::Satpass2::ParseTime::Date::Manip::v6' );
83
84call_m( isa => 'Astro::App::Satpass2::ParseTime', TRUE,
85    'Object is an Astro::App::Satpass2::ParseTime' );
86
87call_m( 'delegate',
88    'Astro::App::Satpass2::ParseTime::Date::Manip::v6',
89    'Delegate is Astro::App::Satpass2::ParseTime::Date::Manip::v6' );
90
91call_m( 'use_perltime', FALSE, 'Does not use perltime' );
92
93call_m( parse => '20100202T120000Z',
94    greg_time_gm( 0, 0, 12, 2, 1, 2010 ),
95    'Parse noon on Groundhog Day 2010' );
96
97my $base = greg_time_gm( 0, 0, 0, 1, 3, 2009 );	# April 1, 2009 GMT;
98use constant ONE_DAY => 86400;			# One day, in seconds.
99use constant HALF_DAY => 43200;			# 12 hours, in seconds.
100
101call_m( base => $base, TRUE, 'Set base time to 01-Apr-2009 GMT' );
102
103call_m( parse => '+0', $base, 'Parse of +0 returns base time' );
104
105call_m( parse => '+1', $base + ONE_DAY,
106    'Parse of +1 returns one day later than base time' );
107
108call_m( parse => '+0', $base + ONE_DAY,
109    'Parse of +0 now returns one day later than base time' );
110
111call_m( 'reset', TRUE, 'Reset to base time' );
112
113call_m( parse => '+0', $base, 'Parse of +0 returns base time again' );
114
115call_m( parse => '+0 12', $base + HALF_DAY,
116    q{Parse of '+0 12' returns base time plus 12 hours} );
117
118call_m( 'reset', TRUE, 'Reset to base time again' );
119
120call_m( parse => '-0', $base, 'Parse of -0 returns base time' );
121
122call_m( parse => '-0 12', $base - HALF_DAY,
123    'Parse of \'-0 12\' returns 12 hours before base time' );
124
125call_m( perltime => 1, TRUE, 'Set perltime true' );
126
127my $time_local = greg_time_local( 0, 0, 0, 1, 0, 2009 );
128call_m( parse => '20090101T000000',
129    $time_local,
130    greg_time_local( 0, 0, 0, 1, 0, 2009 ),
131    'Parse ISO-8601 20090101T000000' )
132    or dump_date_manip( $time_local );
133
134$time_local = greg_time_local( 0, 0, 0, 1, 6, 2009 );
135call_m( parse => '20090701T000000',
136    $time_local,
137    'Parse ISO-8601 20090701T000000' )
138    or dump_date_manip( $time_local );
139
140call_m( perltime => 0, TRUE, 'Set perltime false' );
141
142$time_local = greg_time_local( 0, 0, 0, 1, 0, 2009 );
143call_m( parse => '20090101T000000',
144    $time_local,
145    'Parse ISO-8601 20090101T000000, no help from perltime' )
146    or dump_date_manip( $time_local );
147
148$time_local = greg_time_local( 0, 0, 0, 1, 6, 2009 );
149call_m( parse => '20090701T000000',
150    $time_local,
151    'Parse ISO-8601 20090701T000000, no help from perltime' )
152    or dump_date_manip( $time_local );
153
154my $time_gm = greg_time_gm( 0, 0, 0, 1, 0, 2009 );
155call_m( parse => '20090101T000000Z',
156    $time_gm,
157    'Parse ISO-8601 20090101T000000Z' )
158    or dump_date_manip( $time_gm );
159
160$time_gm = greg_time_gm( 0, 0, 0, 1, 6, 2009 );
161call_m( parse => '20090701T000000Z',
162    $time_gm,
163    'Parse ISO-8601 20090701T000000Z' )
164    or dump_date_manip( $time_gm );
165
166done_testing;
167
1681;
169
170# ex: set textwidth=72 :
171