| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# Test to see if Finance::Quote can at least be loaded and store_date is |
| 4 |
# working |
| 5 |
|
| 6 |
use strict; |
| 7 |
use Test::More; |
| 8 |
|
| 9 |
plan tests => 19; |
| 10 |
|
| 11 |
use Finance::Quote; |
| 12 |
ok(1, "Finance::Quote loaded"); |
| 13 |
|
| 14 |
my $quote = Finance::Quote->new(); |
| 15 |
|
| 16 |
ok($quote, "quote object created"); |
| 17 |
|
| 18 |
|
| 19 |
# Get Today's date |
| 20 |
my ($month, $day, $year2) = (localtime())[4,3,5]; |
| 21 |
$month++; |
| 22 |
my $year4 += $year2 + 1900; # 2007 |
| 23 |
my $year4m += $year2 + 1900 - 1;# 2006 |
| 24 |
$year2 -= 100; # 05 |
| 25 |
my $isotoday = sprintf("%04d-%02d-%02d", $year4, $month, $day); |
| 26 |
my $ustoday = sprintf("%02d/%02d/%04d", $month, $day, $year4); |
| 27 |
|
| 28 |
# Test date functions |
| 29 |
my %info; |
| 30 |
$quote->store_date(\%info, "test", {today => 1}); |
| 31 |
ok($info{"test","isodate"} eq $isotoday,"test->isodate is today"); |
| 32 |
ok($info{"test","date"} eq $ustoday,"test->date is today"); |
| 33 |
|
| 34 |
# Test various permutions of an ISO Date as input |
| 35 |
%info = (); |
| 36 |
$quote->store_date(\%info, "test", {isodate => "2004-12-31"}); |
| 37 |
ok($info{"test","date"} eq "12/31/2004", "ISO date permutation 1"); |
| 38 |
%info = (); |
| 39 |
$quote->store_date(\%info, "test", {isodate => "2004 Dec 31"}); |
| 40 |
ok($info{"test","date"} eq "12/31/2004","ISO date permutation 2"); |
| 41 |
%info = (); |
| 42 |
$quote->store_date(\%info, "test", {isodate => "2004 December 31"}); |
| 43 |
ok($info{"test","date"} eq "12/31/2004","ISO date permutation 3"); |
| 44 |
|
| 45 |
# Test various permutions of an US Date as input |
| 46 |
%info = (); |
| 47 |
$quote->store_date(\%info, "test", {usdate => "12/31/2004"}); |
| 48 |
ok($info{"test","isodate"} eq "2004-12-31","US date permutation 1"); |
| 49 |
%info = (); |
| 50 |
$quote->store_date(\%info, "test", {usdate => "Dec 31, 2004"}); |
| 51 |
ok($info{"test","isodate"} eq "2004-12-31","US date permutation 2"); |
| 52 |
%info = (); |
| 53 |
$quote->store_date(\%info, "test", {usdate => "December 31 2004"}); |
| 54 |
ok($info{"test","isodate"} eq "2004-12-31","US date permutation 3"); |
| 55 |
|
| 56 |
# Test various permutions of an European Date as input |
| 57 |
%info = (); |
| 58 |
$quote->store_date(\%info, "test", {eurodate => "31/12/2004"}); |
| 59 |
ok($info{"test","isodate"} eq "2004-12-31","EUR date permutation 1" ); |
| 60 |
%info = (); |
| 61 |
$quote->store_date(\%info, "test", {eurodate => "31 December 2004"}); |
| 62 |
ok($info{"test","isodate"} eq "2004-12-31","EUR date permutation 2"); |
| 63 |
%info = (); |
| 64 |
$quote->store_date(\%info, "test", {eurodate => "31 Dec, 2004"}); |
| 65 |
ok($info{"test","isodate"} eq "2004-12-31","EUR date permutation 3"); |
| 66 |
|
| 67 |
# Try some other permutions. A recent change to the date handling |
| 68 |
# code changes the behavior if a year is not explicitly provided. Now |
| 69 |
# it will look at the month and decide if the date is in the current |
| 70 |
# year or is from the previous year. This code still has to handle |
| 71 |
# being executed on 12/31, thus the dual tests for each date. |
| 72 |
%info = (); |
| 73 |
$quote->store_date(\%info, "test", {day=>"31", month=>"12"}); |
| 74 |
ok($info{"test","date"} eq "12/31/$year4" || |
| 75 |
$info{"test","date"} eq "12/31/$year4m","test year 1"); |
| 76 |
ok($info{"test","isodate"} eq "$year4-12-31" || |
| 77 |
$info{"test","isodate"} eq "$year4m-12-31","test year 2"); |
| 78 |
%info = (); |
| 79 |
$quote->store_date(\%info, "test", {day=>"31", month=>"December"}); |
| 80 |
ok($info{"test","date"} eq "12/31/$year4" || |
| 81 |
$info{"test","date"} eq "12/31/$year4m","test year 3"); |
| 82 |
ok($info{"test","isodate"} eq "$year4-12-31" || |
| 83 |
$info{"test","isodate"} eq "$year4m-12-31","test year 4"); |
| 84 |
%info = (); |
| 85 |
$quote->store_date(\%info, "test", {day=>"31", month=>"December", year => $year2}); |
| 86 |
ok($info{"test","date"} eq "12/31/$year4" || |
| 87 |
$info{"test","date"} eq "12/31/$year4m","test year 5"); |
| 88 |
ok($info{"test","isodate"} eq "$year4-12-31" || |
| 89 |
$info{"test","isodate"} eq "$year4m-12-31","test year 6"); |