[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proposal, v1



One more remark.
 
+
+sub date_interval {
+    my ($date,$interval,$n) = @_;
+    $date = LedgerSMB::PGDate->from_input($date);
+    $n //= 1;    # Default to 1

Is this one comparison (i.e. 2 dates)? Or one date?
 
+    if ($interval eq 'day'){
+       if ( $n > 0 ) {
+          $date->date->add(days => 1 * $n);
+       } else {
+          $date->date->subtract(days => 1 * -$n);
+       }

Reading the documentation on add() and subtract(), they are syntactic sugar for add_duration() and subtract_duration(). Reading the docs on subtract_duration(), it's simply a wrapper around add($duration->invert), which suggests to me that this code can be half as long by depending on "add(days => $n)" == "subtract(days => -$n)".

In addition, I personally like to use hashes to do input mapping; in this case:

   my %delta_names = (
         day => 'days',
         month => 'months',
         year => 'years',
    );
    my $delta_name = $delta_names{$interval};

       die "Bad interval: $interval" if undefined $delta_name;
       $date->date->add($delta_name => $n);

You probably want "month_ends => 'preserve'" here too, because comparison could use 28, 29, 30 or 31 day months as their basis.


 

--
Bye,

Erik.

http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/
gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
_______________________________________________
Ledger-smb-devel mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-devel