diff options
author | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-05-07 20:53:47 +0000 |
---|---|---|
committer | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-05-07 20:53:47 +0000 |
commit | a817c72bd69c85273951b11814669eb64ef633b5 (patch) | |
tree | 140f4e3c6325d607d685f6455161d86e32b42047 | |
parent | 814644f32d2fb16b4de8b56b25474aeb2dd41dcb (diff) |
Minor tweak to $form->add_date and tests for add_date
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@1158 4979c152-3d1c-0410-bac9-87ea11338e46
-rwxr-xr-x | LedgerSMB/Form.pm | 1 | ||||
-rw-r--r-- | t/03-date-handling.t | 58 |
2 files changed, 57 insertions, 2 deletions
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm index 8ba7eaed..47b25a6e 100755 --- a/LedgerSMB/Form.pm +++ b/LedgerSMB/Form.pm @@ -1425,6 +1425,7 @@ sub add_date { $mm = ( $diff % 12 ); $mm = '12' if $mm == 0; + $yy-- if $mm == 12; $diff = 0; } diff --git a/t/03-date-handling.t b/t/03-date-handling.t index de9e108b..019115a0 100644 --- a/t/03-date-handling.t +++ b/t/03-date-handling.t @@ -3,8 +3,6 @@ # Note: This file assumes good dates, SL behaviour with bad dates is undefined # -#LedgerSMB/Form.pm:1361:sub add_date { - use strict; use warnings; use Test::More 'no_plan'; @@ -276,3 +274,59 @@ foreach my $format (0 .. $#formats) { cmp_ok($form->from_to('2000', '02', '0'), 'eq', $results, "from_to, $fmt, 2000-02, 0 interval (today)"); } + +# $form->add_date checks +# returns undef if no date passed +# valid units: days, weeks, months, years +# all uses in LSMB use days unit +# has no error handling capabilities +foreach my $format (0 .. $#formats) { + $form->{db_dateformat} = $formats[$format][0]; + %myconfig = (dateformat => $formats[$format][0]); + my $fmt = $formats[$format][0]; + my $sep = $formats[$format][1]; + my $yearcount = $formats[$format][2]; + my $start = $fmt; + $start =~ s/(yy)?yy/2000/; + $start =~ s/mm/01/; + $start =~ s/dd/29/; + my $results = $start; + $results =~ s/29/30/; + cmp_ok($form->add_date(\%myconfig, $start, 1, 'days'), 'eq', + $results, "add_date, $fmt, 1 days, 2000-01-29"); + $results =~ s/30/31/; + cmp_ok($form->add_date(\%myconfig, $start, 2, 'days'), 'eq', + $results, "add_date, $fmt, 2 days, 2000-01-29"); + $results =~ s/31/05/; + $results =~ s/01/02/; + cmp_ok($form->add_date(\%myconfig, $start, 1, 'weeks'), 'eq', + $results, "add_date, $fmt, 1 weeks, 2000-01-29"); + $results =~ s/05/12/; + cmp_ok($form->add_date(\%myconfig, $start, 2, 'weeks'), 'eq', + $results, "add_date, $fmt, 2 weeks, 2000-01-29"); + $results =~ s/12/29/; + cmp_ok($form->add_date(\%myconfig, $start, 1, 'months'), 'eq', + $results, "add_date, $fmt, 1 months, 2000-01-29"); + $results =~ s/02/03/; + cmp_ok($form->add_date(\%myconfig, $start, 2, 'months'), 'eq', + $results, "add_date, $fmt, 2 months, 2000-01-29"); + $results = $start; + $results =~ s/01/11/; + cmp_ok($form->add_date(\%myconfig, $start, 10, 'months'), 'eq', + $results, "add_date, $fmt, 10 months, 2000-01-29"); + $results = $start; + $results =~ s/01/12/; + cmp_ok($form->add_date(\%myconfig, $start, 11, 'months'), 'eq', + $results, "add_date, $fmt, 11 months, 2000-01-29"); + $results = $start; + $results =~ s/2000/2001/; + cmp_ok($form->add_date(\%myconfig, $start, 12, 'months'), 'eq', + $results, "add_date, $fmt, 12 months, 2000-01-29"); + cmp_ok($form->add_date(\%myconfig, $start, 1, 'years'), 'eq', + $results, "add_date, $fmt, 1 years, 2000-01-29"); + $results =~ s/2001/2002/; + cmp_ok($form->add_date(\%myconfig, $start, 2, 'years'), 'eq', + $results, "add_date, $fmt, 2 years, 2000-01-29"); +} +ok(!defined $form->add_date(\%myconfig), + 'add_date, undef if no date'); |