| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use warnings; |
| 4 |
use strict; |
| 5 |
use Test::Inter; |
| 6 |
$::ti = new Test::Inter $0; |
| 7 |
require "tests.pl"; |
| 8 |
|
| 9 |
my $obj = new Date::Manip::Recur; |
| 10 |
$obj->config("forcedate","2000-01-21-00:00:00,America/New_York"); |
| 11 |
|
| 12 |
sub test { |
| 13 |
my ($op,$arg) = @_; |
| 14 |
my ($date,$err); |
| 15 |
|
| 16 |
if ($op eq 'freq') { |
| 17 |
$err = $obj->frequency($arg); |
| 18 |
return $obj->err() if ($err); |
| 19 |
return 0; |
| 20 |
|
| 21 |
} elsif ($op eq 'basedate') { |
| 22 |
$err = $obj->basedate($arg); |
| 23 |
return $obj->err() if ($err); |
| 24 |
return 0; |
| 25 |
|
| 26 |
} elsif ($op eq 'start') { |
| 27 |
$err = $obj->start($arg); |
| 28 |
return $obj->err() if ($err); |
| 29 |
return 0; |
| 30 |
|
| 31 |
} elsif ($op eq 'end') { |
| 32 |
$err = $obj->end($arg); |
| 33 |
return $obj->err() if ($err); |
| 34 |
return 0; |
| 35 |
|
| 36 |
} elsif ($op eq 'next') { |
| 37 |
($date,$err) = $obj->next($arg); |
| 38 |
return $err if ($err); |
| 39 |
return $date if (! defined($date)); |
| 40 |
my $val = $date->value(); |
| 41 |
return $val; |
| 42 |
|
| 43 |
} elsif ($op eq 'prev') { |
| 44 |
($date,$err) = $obj->prev($arg); |
| 45 |
return $err if ($err); |
| 46 |
return $date if (! defined($date)); |
| 47 |
my $val = $date->value(); |
| 48 |
return $val; |
| 49 |
|
| 50 |
} elsif ($op eq 'nth') { |
| 51 |
($date,$err) = $obj->nth($arg); |
| 52 |
return $err if ($err); |
| 53 |
return $date if (! defined($date)); |
| 54 |
my $val = $date->value(); |
| 55 |
return $val; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
my $tests=" |
| 60 |
|
| 61 |
freq 1*2:0:4:12:0:0 => 0 |
| 62 |
|
| 63 |
basedate 1999-12-30-00:00:00 => 0 |
| 64 |
|
| 65 |
nth 0 => 1999020412:00:00 |
| 66 |
|
| 67 |
nth 2 => 2001020412:00:00 |
| 68 |
|
| 69 |
nth -2 => 1997020412:00:00 |
| 70 |
|
| 71 |
# 31st of every month |
| 72 |
|
| 73 |
freq 0:1*0:31:12:0:0 => 0 |
| 74 |
|
| 75 |
basedate 2005-01-27-00:00:00 => 0 |
| 76 |
|
| 77 |
nth 0 => 2005013112:00:00 |
| 78 |
|
| 79 |
nth 1 => __undef__ |
| 80 |
|
| 81 |
nth 2 => 2005033112:00:00 |
| 82 |
|
| 83 |
nth -1 => 2004123112:00:00 |
| 84 |
|
| 85 |
# d=15--15 |
| 86 |
|
| 87 |
freq 0:1*0:15--15:12:0:0 => 0 |
| 88 |
|
| 89 |
basedate 2005-01-27-00:00:00 => 0 |
| 90 |
|
| 91 |
nth 0 => 2005011512:00:00 |
| 92 |
|
| 93 |
nth 1 => 2005011612:00:00 |
| 94 |
|
| 95 |
nth 2 => 2005011712:00:00 |
| 96 |
|
| 97 |
nth 3 => 2005031512:00:00 |
| 98 |
|
| 99 |
# DST transition dates |
| 100 |
|
| 101 |
freq 0:0:0:0:1*30:0 => 0 |
| 102 |
|
| 103 |
basedate 2010-03-14-00:00:01 => 0 |
| 104 |
|
| 105 |
nth 0 => 2010031400:30:00 |
| 106 |
|
| 107 |
nth 1 => 2010031401:30:00 |
| 108 |
|
| 109 |
nth 2 => 2010031403:30:00 |
| 110 |
|
| 111 |
freq 0:0:0:0:1*30:0 => 0 |
| 112 |
|
| 113 |
basedate 2010-11-07-00:00:01 => 0 |
| 114 |
|
| 115 |
nth 0 => 2010110700:30:00 |
| 116 |
|
| 117 |
nth 1 => 2010110701:30:00 |
| 118 |
|
| 119 |
nth 1 => 2010110701:30:00 |
| 120 |
|
| 121 |
freq 0:0:0:1*02:30:00 => 0 |
| 122 |
|
| 123 |
basedate 2010-03-13-00:00:00 => 0 |
| 124 |
|
| 125 |
nth 0 => 2010031302:30:00 |
| 126 |
|
| 127 |
nth 1 => __undef__ |
| 128 |
|
| 129 |
nth 2 => 2010031502:30:00 |
| 130 |
|
| 131 |
freq *2010:1:0:4-5:12-13:0:0 => 0 |
| 132 |
|
| 133 |
nth 0 => 2010010412:00:00 |
| 134 |
|
| 135 |
nth 1 => 2010010413:00:00 |
| 136 |
|
| 137 |
nth 2 => 2010010512:00:00 |
| 138 |
|
| 139 |
nth 3 => 2010010513:00:00 |
| 140 |
|
| 141 |
nth -1 => __undef__ |
| 142 |
|
| 143 |
nth 4 => __undef__ |
| 144 |
|
| 145 |
freq *2010:1-4:0:31:12:0:0 => 0 |
| 146 |
|
| 147 |
nth 0 => 2010013112:00:00 |
| 148 |
|
| 149 |
nth 1 => 2010033112:00:00 |
| 150 |
|
| 151 |
nth 2 => __undef__ |
| 152 |
|
| 153 |
nth -1 => __undef__ |
| 154 |
|
| 155 |
freq *2010:1-4:0:31:12:0:0 => 0 |
| 156 |
|
| 157 |
next => 2010013112:00:00 |
| 158 |
|
| 159 |
next => 2010033112:00:00 |
| 160 |
|
| 161 |
next => __undef__ |
| 162 |
|
| 163 |
prev => 2010033112:00:00 |
| 164 |
|
| 165 |
prev => 2010013112:00:00 |
| 166 |
|
| 167 |
prev => __undef__ |
| 168 |
|
| 169 |
freq *2010:1-4:0:31:12:0:0 => 0 |
| 170 |
|
| 171 |
prev => 2010033112:00:00 |
| 172 |
|
| 173 |
prev => 2010013112:00:00 |
| 174 |
|
| 175 |
prev => __undef__ |
| 176 |
|
| 177 |
freq 0:1*0:31:12:0:0 => 0 |
| 178 |
|
| 179 |
basedate 2005-01-27-00:00:00 => 0 |
| 180 |
|
| 181 |
next => 2005013112:00:00 |
| 182 |
|
| 183 |
next => 2005033112:00:00 |
| 184 |
|
| 185 |
prev => 2005013112:00:00 |
| 186 |
|
| 187 |
freq 0:1*0:31:12:0:0 => 0 |
| 188 |
|
| 189 |
basedate 2005-01-27-00:00:00 => 0 |
| 190 |
|
| 191 |
prev => 2004123112:00:00 |
| 192 |
|
| 193 |
freq 0:1*0:31:12:0:0 => 0 |
| 194 |
|
| 195 |
basedate 2005-02-27-00:00:00 => 0 |
| 196 |
|
| 197 |
next => 2005033112:00:00 |
| 198 |
|
| 199 |
freq 0:1*0:31:12:0:0 => 0 |
| 200 |
|
| 201 |
basedate 2005-02-27-00:00:00 => 0 |
| 202 |
|
| 203 |
prev => 2005013112:00:00 |
| 204 |
|
| 205 |
freq 0:1*0:31:12:0:0 => 0 |
| 206 |
|
| 207 |
basedate 2005-01-27-00:00:00 => 0 |
| 208 |
|
| 209 |
start 2007-01-01-00:00:00 => 0 |
| 210 |
|
| 211 |
end 2007-12-31-00:00:00 => 0 |
| 212 |
|
| 213 |
next => 2007013112:00:00 |
| 214 |
|
| 215 |
freq 0:1*0:31:12:0:0 => 0 |
| 216 |
|
| 217 |
basedate 2005-01-27-00:00:00 => 0 |
| 218 |
|
| 219 |
start 2007-01-01-00:00:00 => 0 |
| 220 |
|
| 221 |
end 2007-12-31-23:59:59 => 0 |
| 222 |
|
| 223 |
prev => 2007123112:00:00 |
| 224 |
|
| 225 |
# next/prev when there are no dates |
| 226 |
|
| 227 |
freq 0:0:0:1*17:00:00 => 0 |
| 228 |
|
| 229 |
start 2020101000:00:00 => 0 |
| 230 |
|
| 231 |
end 2020101000:00:00 => 0 |
| 232 |
|
| 233 |
next => 'Not found' |
| 234 |
|
| 235 |
prev => 'Not found' |
| 236 |
|
| 237 |
"; |
| 238 |
|
| 239 |
$::ti->tests(func => \&test, |
| 240 |
tests => $tests); |
| 241 |
$::ti->done_testing(); |
| 242 |
|
| 243 |
#Local Variables: |
| 244 |
#mode: cperl |
| 245 |
#indent-tabs-mode: nil |
| 246 |
#cperl-indent-level: 3 |
| 247 |
#cperl-continued-statement-offset: 2 |
| 248 |
#cperl-continued-brace-offset: 0 |
| 249 |
#cperl-brace-offset: 0 |
| 250 |
#cperl-brace-imaginary-offset: 0 |
| 251 |
#cperl-label-offset: 0 |
| 252 |
#End: |