koha-cvs
[Top][All Lists]
Advanced

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

[Koha-cvs] koha/intranet/modules/C4 Date.pm Serials.pm [rel_TG]


From: Tumer Garip
Subject: [Koha-cvs] koha/intranet/modules/C4 Date.pm Serials.pm [rel_TG]
Date: Sun, 11 Mar 2007 20:03:27 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         rel_TG
Changes by:     Tumer Garip <tgarip1957>        07/03/11 20:03:27

Modified files:
        intranet/modules/C4: Date.pm Serials.pm 

Log message:
        DateTime removed now uses Date::Calc

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/modules/C4/Date.pm?cvsroot=koha&only_with_tag=rel_TG&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/modules/C4/Serials.pm?cvsroot=koha&only_with_tag=rel_TG&r1=1.1.2.1&r2=1.1.2.2

Patches:
Index: Date.pm
===================================================================
RCS file: /sources/koha/koha/intranet/modules/C4/Attic/Date.pm,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- Date.pm     10 Mar 2007 01:35:34 -0000      1.1.2.1
+++ Date.pm     11 Mar 2007 20:03:27 -0000      1.1.2.2
@@ -17,22 +17,19 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Date.pm,v 1.1.2.1 2007/03/10 01:35:34 tgarip1957 Exp $
-
+# $Id: Date.pm,v 1.1.2.2 2007/03/11 20:03:27 tgarip1957 Exp $
+##changed to use Date::Calc
 package C4::Date;
 
 use strict;
 use C4::Context;
-use DateTime;
-use DateTime::Format::ISO8601;
-use DateTime::Format::Strptime;
-use DateTime::Format::Duration;
-use POSIX qw(ceil floor);
+use Date::Calc qw(:all);
+
 require Exporter;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
-$VERSION = do { my @v = '$Revision: 1.1.2.1 $' =~ /\d+/g; shift(@v) . "." . 
join( "_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = do { my @v = '$Revision: 1.1.2.2 $' =~ /\d+/g; shift(@v) . "." . 
join( "_", map { sprintf "%03d", $_ } @v ); };
 
 @ISA = qw(Exporter);
 
@@ -42,7 +39,7 @@
   &format_date_in_iso
   &get_date_format_string_for_DHTMLcalendar
   &DATE_diff &DATE_Add
-&get_today &DATE_Add_Duration &DATE_obj &get_duration
+&get_today 
 &DATE_subtract
 );
 
@@ -90,129 +87,146 @@
     }
 }
 
-sub format_date {
+sub format_date
+{
     my $olddate = shift;
     my $newdate;
-    if ( !$olddate || $olddate eq "0000-00-00" ) {
+
+       if ( ! $olddate )
+       {
         return "";
     }
-               $olddate=~s/-//g;
-                $olddate=substr($olddate,0,8);
-    my $dateformat = get_date_format();
-eval{$newdate =DateTime::Format::ISO8601->parse_datetime($olddate);};
-if ($@ || !$newdate){
-##MARC21 tag 008 has this format YYMMDD
-my $parser =    DateTime::Format::Strptime->new( pattern => '%y%m%d' );
-        $newdate =$parser->parse_datetime($olddate);
-}
-if (!$newdate){
-return ""; #### some script call format_date more than once --FIX scripts
-}
-
-    if ( $dateformat eq "us" ) {
-      return $newdate->mdy('/');
     
+#     warn $olddate;
+#     $olddate=~s#/|\.|-##g;
+    my ($year,$month,$day)=Parse_Date($olddate);
+    ($year,$month,$day)=split /-|\/|\.|:/,$olddate unless ($year && $month);
+#      warn "$olddate annee $year mois $month jour $day";
+    if ($year>0 && $month>0){
+      my $dateformat = get_date_format();
+#      $dateformat="metric" if (index(":",$olddate)>0);
+      if ( $dateformat eq "us" )
+      {
+          $newdate = sprintf("%02d/%02d/%04d",$month,$day,$year);
     }
-    elsif ( $dateformat eq "metric" ) {
-        return $newdate->dmy('/');
+      elsif ( $dateformat eq "metric" )
+      {
+          $newdate = sprintf("%02d/%02d/%04d",$day,$month,$year);
     }
-    elsif ( $dateformat eq "iso" ) {
-        return $newdate->ymd;
+      elsif ( $dateformat eq "iso" )
+      {
+  #            Date_Init("DateFormat=iso");
+          $newdate = sprintf("%04d-%02d-%02d",$year,$month,$day);
     }
-    else {
-        return
-"Invalid date format: $dateformat. Please change in system preferences";
+      else
+      {
+          return "Invalid date format: $dateformat. Please change in system 
preferences";
     }
-
+#       warn "newdate :$newdate";
+    }
+    return $newdate;
 }
 
-sub format_date_in_iso {
+
+sub format_date_in_iso
+{
     my $olddate = shift;
     my $newdate;
-  my $parser;
-    if ( !$olddate || $olddate eq "0000-00-00" ) {
+
+    if ( ! $olddate )
+    {
         return "";
     }
+    if (check_whether_iso($olddate)){
+      return $olddate;
+    } else {
+      my $dateformat = get_date_format();
+      my ($year,$month,$day);
+      my @date;
+      my $tmpolddate=$olddate;
+      $tmpolddate=~s#/|\.|-|\\##g;
+      $dateformat="metric" if (index(":",$olddate)>0);
+      if ( $dateformat eq "us" )
+      {
+        ($month,$day,$year)=split /-|\/|\.|:/,$olddate unless ($year && 
$month);
+        if ($month>0 && $day >0){
+              @date = Decode_Date_US($tmpolddate);
+        } else {
+          @date=($year, $month,$day)
+        }
+      }
+      elsif ( $dateformat eq "metric" )
+      {
+        ($day,$month,$year)=split /-|\/|\.|:/,$olddate unless ($year && 
$month);
+        if ($month>0 && $day >0){
+              @date = Decode_Date_EU($tmpolddate);
+        } else {
+          @date=($year, $month,$day)
+        }
+      }
+      elsif ( $dateformat eq "iso" )
+      {
+        ($year,$month,$day)=split /-|\/|\.|:/,$olddate unless ($year && 
$month);
+        if ($month>0 && $day >0){
+          @date=($year, $month,$day) if (check_date($year,$month,$day));
+        } else {
+          @date=($year, $month,$day)
+        }
+      }
+      else
+      {
+          return "9999-99-99";
+      }
+      $newdate = sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
+      return $newdate;
+    }
+}
 
-$parser =    DateTime::Format::Strptime->new( pattern => '%d/%m/%Y' );
-        $newdate =$parser->parse_datetime($olddate);
-if (!$newdate){
-$parser =    DateTime::Format::Strptime->new( pattern => '%m/%d/%Y' );
-$newdate =$parser->parse_datetime($olddate);
-}
-if (!$newdate){
- $parser =    DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' );
-$newdate =$parser->parse_datetime($olddate);
-}
- if (!$newdate){
- $parser =    DateTime::Format::Strptime->new( pattern => '%y-%m-%d' );
-$newdate =$parser->parse_datetime($olddate);
+sub check_whether_iso
+{
+    my $olddate = shift;
+    my @olddate= split /\-/,$olddate ;
+    return 1 if (length($olddate[0])==4 && length($olddate[1])<=2 && 
length($olddate[2])<=2);
+    return 0;
 }
   
-    return $newdate->ymd if $newdate;
+sub get_today{
+my ($year,$month,$day)=Today();
+return sprintf("%04d-%02d-%02d",$year,$month,$day);
 }
+
+###Utility functions for serials management
 sub DATE_diff {
 ## returns 1 if date1>date2 0 if date1==date2 -1 if date1<date2
 my ($date1,$date2)address@hidden;
-my $dt1=DateTime::Format::ISO8601->parse_datetime($date1);
-my $dt2=DateTime::Format::ISO8601->parse_datetime($date2);
-my $diff=DateTime->compare( $dt1, $dt2 );
-return $diff;
+my ($year1,$month1,$day1)=Parse_Date($date1);
+my ($year2,$month2,$day2)=Parse_Date($date2);
+return Delta_Days($year1,$month1,$day1, $year2,$month2,$day2) 
 }
+
 sub DATE_Add {
 ## $amount in days
 my ($date,$amount)address@hidden;
-my $dt1=DateTime::Format::ISO8601->parse_datetime($date);
-$dt1->add( days=>$amount );
-return $dt1->ymd;
-}
-sub DATE_Add_Duration {
-## Similar as above but uses Duration object as amount --used heavily in 
serials
-my ($date,$amount)address@hidden;
-my $dt1=DateTime::Format::ISO8601->parse_datetime($date);
-$dt1->add_duration($amount) ;
-return $dt1->ymd;
-}
-sub get_today{
-my $dt=DateTime->now;
-$dt->add(hours=>2);
-return $dt->ymd;
-}
-
-sub DATE_obj{
-# only send iso dates to this
-my $date=shift;
-   my $parser =    DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' );
-      my  $newdate =$parser->parse_datetime($date);
-return $newdate;
-}
-sub get_duration{
-my $period=shift;
-
-my $parse;
-if ($period=~/ays/){
-$parse="\%e days";
-}elsif ($period=~/week/){
-$parse="\%W weeks";
-}elsif ($period=~/year/){
-$parse="\%Y years";
-}elsif ($period=~/onth/){
-$parse="\%m months";
+my ($year,$month,$day)=Parse_Date($date);
+($year,$month,$day) = Add_Delta_Days($year,$month,$day, $amount);
+return sprintf("%04d-%02d-%02d",$year,$month,$day);
 }
 
-my $parser=DateTime::Format::Duration->new(pattern => $parse  );
-       my $duration=$parser->parse_duration($period);
 
-return $duration;
 
-}
+
+
+
+
+
 sub DATE_subtract{
 my ($date1,$date2)address@hidden;
-my $dt1=DateTime::Format::ISO8601->parse_datetime($date1);
-my $dt2=DateTime::Format::ISO8601->parse_datetime($date2);
-my $dur=$dt2->subtract_datetime_absolute($dt1);## in seconds
-my $days=$dur->seconds/(60*60*24);
-return floor($days);
+my ($year1,$month1,$day1)=Parse_Date($date1);
+my ($year2,$month2,$day2)=Parse_Date($date2);
+my $lower = Date_to_Days($year1,$month1,$day1);
+ my $upper = Date_to_Days($year2,$month2,$day2);
+
+return ($lower-$upper);
 }
 1;
 __END__

Index: Serials.pm
===================================================================
RCS file: /sources/koha/koha/intranet/modules/C4/Attic/Serials.pm,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- Serials.pm  10 Mar 2007 01:35:34 -0000      1.1.2.1
+++ Serials.pm  11 Mar 2007 20:03:27 -0000      1.1.2.2
@@ -17,10 +17,11 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Serials.pm,v 1.1.2.1 2007/03/10 01:35:34 tgarip1957 Exp $
-
+# $Id: Serials.pm,v 1.1.2.2 2007/03/11 20:03:27 tgarip1957 Exp $
+#Date::Calc added
 use strict;
 use C4::Date;
+use Date::Calc qw(:all);
 use C4::Suggestions;
 use C4::Biblio;
 use C4::Search;
@@ -30,7 +31,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.1.2.1 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.1.2.2 $' =~ /\d+/g;
         shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 
@@ -758,20 +759,33 @@
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
     my $subscription = GetSubscription($subscriptionid);
-    my $enddate=$subscription->{startdate};
-    # we don't do the same test if the subscription is based on X numbers or 
on X weeks/months
-    if ($subscription->{numberlength}) {
+    my $enddate          = $subscription->{startdate};
+
+# we don't do the same test if the subscription is based on X numbers or on X 
weeks/months
+#     warn "SUBSCRIPTIONID :$subscriptionid";
+#     use Data::Dumper; warn Dumper($subscription);
+
+    if ( $subscription->{numberlength} ) {
         #calculate the date of the last issue.
-        for (my $i=1;$i<=$subscription->{numberlength};$i++) {
-            $enddate = GetNextDate($enddate,$subscription);
-        }
-    }
-    else {
-       my $duration;
-        $duration=get_duration($subscription->{monthlength}." months") if 
($subscription->{monthlength});
-        $duration=get_duration($subscription->{weeklength}." weeks") if 
($subscription->{weeklength});
-        $enddate = DATE_Add_Duration($subscription->{startdate},$duration) ;
+        my $length = $subscription->{numberlength};
+#         warn "ENDDATE ".$enddate;
+        for ( my $i = 1 ; $i <= $length ; $i++ ) {
+            $enddate = GetNextDate( $enddate, $subscription );
+#             warn "AFTER ENDDATE ".$enddate;
+        }
+    }
+    elsif ( $subscription->{monthlength} ){
+#         warn "dateCHECKRESERV :".$subscription->{startdate};
+        my @date=split (/-/,$subscription->{startdate});
+        my @enddate = 
Add_Delta_YM($date[0],$date[1],$date[2],0,$subscription->{monthlength});
+        $enddate=sprintf("%04d-%02d-%02d",$enddate[0],$enddate[1],$enddate[2]);
+    } elsif ( $subscription->{weeklength} ){
+        my @date=split (/-/,$subscription->{startdate});
+
+        my @enddate = 
Add_Delta_Days($date[0],$date[1],$date[2],$subscription->{weeklength}*7);
+        $enddate=sprintf("%04d-%02d-%02d",$enddate[0],$enddate[1],$enddate[2]);
     }
+#     warn "date de fin :$enddate";
     return $enddate;
 }
 
@@ -1196,23 +1210,7 @@
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
     my $subscription = GetSubscription($subscriptionid);
-    # we don't do the same test if the subscription is based on X numbers or 
on X weeks/months
-    if ($subscription->{numberlength} ) {
-        my $query = qq|
-            SELECT count(*)
-            FROM   serial
-            WHERE  subscriptionid=? AND planneddate>=?
-        |;
-        my $sth = $dbh->prepare($query);
-        $sth->execute($subscriptionid,$subscription->{startdate});
-        my $res = $sth->fetchrow;
-        if ($subscription->{numberlength}>=$res) {
-            return 0;
-        } else {
-            return 1;
-        }
-    } else {
-        #a little bit more tricky if based on X weeks/months : search if the 
latest issue waited is not after subscription startdate + duration
+    my $expirationdate   = GetSubscriptionExpirationDate($subscriptionid);
         my $query = qq|
             SELECT max(planneddate)
             FROM   serial
@@ -1220,16 +1218,13 @@
         |;
         my $sth = $dbh->prepare($query);
         $sth->execute($subscriptionid);
-        my $res = $sth->fetchrow;
-        my $endofsubscriptiondate;
-       my $duration;
-        $duration=get_duration($subscription->{monthlength}." months") if 
($subscription->{monthlength});
-       $duration=get_duration($subscription->{weeklength}." weeks") if 
($subscription->{weeklength});
-
-        $endofsubscriptiondate = 
DATE_Add_Duration($subscription->{startdate},$duration) ;
-        return 1 if ($res ge $endofsubscriptiondate);
+    my ($res) = $sth->fetchrow  ;
+    my @res=split (/-/,$res);
+    my @endofsubscriptiondate=split(/-/,$expirationdate);
+    return 1 if ( (@endofsubscriptiondate && 
Delta_Days($res[0],$res[1],$res[2],
+                  
$endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2]) 
<= 0)
+                  || (!$res));
         return 0;
-    }
 }
 
 =head2 SetDistributedto
@@ -1626,46 +1621,38 @@
     my ($subscriptionid) = @_;
     my $dbh = C4::Context->dbh;
     my $subscription = GetSubscription($subscriptionid);
-    # we don't do the same test if the subscription is based on X numbers or 
on X weeks/months
-    if ($subscription->{numberlength}) {
-       my $sth = $dbh->prepare("select count(*) from serial where 
subscriptionid=?  and planneddate>=?");
-       $sth->execute($subscriptionid,$subscription->{startdate});
-       my $res = $sth->fetchrow;
-       # warn "length: ".$subscription->{numberlength}." vs count: ".$res;
-       if ($subscription->{numberlength}==$res) {
-           return 1;
-       } else {
-           return 0;
-       }
-    } else {
-       # a little bit more tricky if based on X weeks/months : search if the 
latest issue waited is not after subscription startdate + duration
-       my $sth = $dbh->prepare("select max(planneddate) from serial where 
subscriptionid=?");
-       $sth->execute($subscriptionid);
-       my $res = $sth->fetchrow;
-       my $endofsubscriptiondate;
-my $duration;
-        $duration=get_duration($subscription->{monthlength}." months") if 
($subscription->{monthlength});
-        $duration=get_duration($subscription->{weeklength}." weeks") if 
($subscription->{weeklength});
-
-        $endofsubscriptiondate = 
DATE_Add_Duration($subscription->{startdate},$duration) ;
+    my $expirationdate   = GetSubscriptionExpirationDate($subscriptionid);
+    my $sth =
+      $dbh->prepare(
+        "select max(planneddate) from serial where subscriptionid=?");
+    $sth->execute($subscriptionid);
+    my ($res) = $sth->fetchrow ;
+#     warn "date expiration : ".$expirationdate." date courante ".$res;
+    my @res=split /-/,$res;
+    my @endofsubscriptiondate=split/-/,$expirationdate;
        my $per = $subscription->{'periodicity'};
-       my $x = 0;
-       if ($per == 1) { $x = '1 days'; }
-       if ($per == 2) { $x = '1 weeks'; }
-       if ($per == 3) { $x = '2 weeks'; }
-       if ($per == 4) { $x = '3 weeks'; }
-       if ($per == 5) { $x = '1 months'; }
-       if ($per == 6) { $x = '2 months'; }
-       if ($per == 7 || $per == 8) { $x = '3 months'; }
-       if ($per == 9) { $x = '6 months'; }
-       if ($per == 10) { $x = '1 years'; }
-       if ($per == 11) { $x = '2 years'; }
-       my $duration=get_duration("-".$x) ;
-       my $datebeforeend = 
DATE_Add_Duration($endofsubscriptiondate,$duration); # if 
($subscription->{weeklength});
+    my $x;
+    if ( $per == 1 ) {$x=7;}
+    if ( $per == 2 ) {$x=7; }
+    if ( $per == 3 ) {$x=14;}
+    if ( $per == 4 ) { $x = 21; }
+    if ( $per == 5 ) { $x = 31; }
+    if ( $per == 6 ) { $x = 62; }
+    if ( $per == 7 || $per == 8 ) { $x = 93; }
+    if ( $per == 9 )  { $x = 190; }
+    if ( $per == 10 ) { $x = 365; }
+    if ( $per == 11 ) { $x = 730; }
+    my @datebeforeend=Add_Delta_Days(  
$endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2],
+                  - (3 * $x)) if (@endofsubscriptiondate);
        # warn "DATE BEFORE END: $datebeforeend";
-       return 1 if ($res >= $datebeforeend && $res < $endofsubscriptiondate);
+    return 1 if ( @res && 
+                  (@datebeforeend && 
+                      Delta_Days($res[0],$res[1],$res[2],
+                      $datebeforeend[0],$datebeforeend[1],$datebeforeend[2]) 
<= 0) && 
+                  (@endofsubscriptiondate && 
+                      Delta_Days($res[0],$res[1],$res[2],
+                      
$endofsubscriptiondate[0],$endofsubscriptiondate[1],$endofsubscriptiondate[2]) 
>= 0) );
        return 0;
-    }
 }
 
 
@@ -1688,128 +1675,115 @@
 
 =cut
 sub GetNextDate {
-    my ($planneddate,$subscription) = @_;
-    my @irreg = split(/\|/,$subscription->{irregularity});
- my $dateobj=DATE_obj($planneddate);
-    my $dayofweek = $dateobj->day_of_week;
-  my $month=$dateobj->month;
-    my $resultdate;
-
-    if ($subscription->{periodicity} == 1) {
-       my %irreghash;
-       for(my $i=0;$i<@irreg;$i++){
-       $irreghash{$irreg[$i]}=1;
-       }
-my $duration=get_duration("1 days");
-       for(my $i=0;$i<@irreg;$i++){
-           if($dayofweek == 7){ $dayofweek = 0; }
+    my ( $planneddate, $subscription ) = @_;
+    my @irreg = split( /\,/, $subscription->{irregularity} );
+
+    #date supposed to be in ISO.
 
-           if($irreghash{$dayofweek+1}){
-               $planneddate = DATE_Add_Duration($planneddate,$duration);
+    my ( $year, $month, $day ) = split(/-/, $planneddate);
+    $month=1 unless ($month);
+    $day=1 unless ($day);
+    my @resultdate;
+
+    #       warn "DOW $dayofweek";
+    if ( $subscription->{periodicity} == 1 ) {
+        my $dayofweek = Day_of_Week( $year,$month, $day );
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            $dayofweek = 0 if ( $dayofweek == 7 ); 
+            if ( in_array( ($dayofweek + 1), @irreg ) ) {
+                ($year,$month,$day) = Add_Delta_Days($year,$month, $day , 1 );
                $dayofweek++;
            }
        }
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
+        @resultdate = Add_Delta_Days($year,$month, $day , 1 );
+    }
+    if ( $subscription->{periodicity} == 2 ) {
+        my ($wkno,$year) = Week_of_Year( $year,$month, $day );
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $irreg[$i] == (($wkno!=51)?($wkno +1) % 52 :52)) {
+                ($year,$month,$day) = Add_Delta_Days($year,$month, $day , 7 );
+                $wkno=(($wkno!=51)?($wkno +1) % 52 :52);
+            }
+        }
+        @resultdate = Add_Delta_Days( $year,$month, $day, 7);
+    }
+    if ( $subscription->{periodicity} == 3 ) {
+        my ($wkno,$year) = Week_of_Year( $year,$month, $day );
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $irreg[$i] == (($wkno!=50)?($wkno +2) % 52 :52)) {
+            ### BUGFIX was previously +1 ^
+                ($year,$month,$day) = Add_Delta_Days($year,$month, $day , 14 );
+                $wkno=(($wkno!=50)?($wkno +2) % 52 :52);
+            }
+        }
+        @resultdate = Add_Delta_Days($year,$month, $day , 14 );
+    }
+    if ( $subscription->{periodicity} == 4 ) {
+        my ($wkno,$year) = Week_of_Year( $year,$month, $day );
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $irreg[$i] == (($wkno!=49)?($wkno +3) % 52 :52)) {
+                ($year,$month,$day) = Add_Delta_Days($year,$month, $day , 21 );
+                $wkno=(($wkno!=49)?($wkno +3) % 52 :52);
+            }
+        }
+        @resultdate = Add_Delta_Days($year,$month, $day , 21 );
+    }
+    my $tmpmonth=$month;
+    if ( $subscription->{periodicity} == 5 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $irreg[$i] == (($tmpmonth!=11)?($tmpmonth +1) % 12 :12)) {
+                ($year,$month,$day) = Add_Delta_YMD($year,$month, $day ,0,1,0 
);
+                $tmpmonth=(($tmpmonth!=11)?($tmpmonth +1) % 12 :12);
+            }
+        }
+        @resultdate = Add_Delta_YMD($year,$month, $day ,0,1,0 );
+    }
+    if ( $subscription->{periodicity} == 6 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $irreg[$i] == (($tmpmonth!=10)?($tmpmonth +2) % 12 :12)) {
+                ($year,$month,$day) = Add_Delta_YMD($year,$month, $day ,0,2,0 
);
+                $tmpmonth=(($tmpmonth!=10)?($tmpmonth + 2) % 12 :12);
+            }
+        }
+        @resultdate = Add_Delta_YMD($year,$month, $day, 0, 2,0 );
+    }
+    if ( $subscription->{periodicity} == 7 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $irreg[$i] == (($tmpmonth!=9)?($tmpmonth +3) % 12 :12)) {
+                ($year,$month,$day) = Add_Delta_YMD($year,$month, $day, 0, 3,0 
);
+                $tmpmonth=(($tmpmonth!=9)?($tmpmonth + 3) % 12 :12);
+            }
+        }
+        @resultdate = Add_Delta_YMD($year,$month, $day, 0, 3, 0);
+    }
+    if ( $subscription->{periodicity} == 8 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $irreg[$i] == (($tmpmonth!=9)?($tmpmonth +3) % 12 :12)) {
+                ($year,$month,$day) = Add_Delta_YMD($year,$month, $day, 0, 3,0 
);
+                $tmpmonth=(($tmpmonth!=9)?($tmpmonth + 3) % 12 :12);
+            }
+        }
+        @resultdate = Add_Delta_YMD($year,$month, $day, 0, 3, 0);
+    }
+    if ( $subscription->{periodicity} == 9 ) {
+        for ( my $i = 0 ; $i < @irreg ; $i++ ) {
+            if ( $irreg[$i] == (($tmpmonth!=9)?($tmpmonth +3) % 12 :12)) {
+            ### BUFIX Seems to need more Than One ?
+                ($year,$month,$day) = Add_Delta_YM($year,$month, $day, 0, 6 );
+                $tmpmonth=(($tmpmonth!=6)?($tmpmonth + 6) % 12 :12);
+            }
+        }
+        @resultdate = Add_Delta_YM($year,$month, $day, 0, 6);
+    }
+    if ( $subscription->{periodicity} == 10 ) {
+        @resultdate = Add_Delta_YM($year,$month, $day, 1, 0 );
     }
-    if ($subscription->{periodicity} == 2) {
-       my $wkno = $dateobj->week_number;
-my $duration=get_duration("1 weeks");
-       for(my $i = 0;$i < @irreg; $i++){
-           if($wkno > 52) { $wkno = 0; } # need to rollover at January
-           if($irreg[$i] == ($wkno+1)){
-               $planneddate = DATE_Add_Duration($planneddate,$duration);
-               $wkno++;
-           }
-       }
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
-    }
-    if ($subscription->{periodicity} == 3) {
-       my $wkno = $dateobj->week_number;
-my $duration=get_duration("2 weeks");
-       for(my $i = 0;$i < @irreg; $i++){
-           if($wkno > 52) { $wkno = 0; } # need to rollover at January
-           if($irreg[$i] == ($wkno+1)){
-               $planneddate = DATE_Add_Duration($planneddate,$duration);
-               $wkno++;
-           }
-       }
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
-    }
-    if ($subscription->{periodicity} == 4) {
-       my $wkno = $dateobj->week_number;
-my $duration=get_duration("3 weeks");
-       for(my $i = 0;$i < @irreg; $i++){
-           if($wkno > 52) { $wkno = 0; } # need to rollover at January
-           if($irreg[$i] == ($wkno+1)){
-               $planneddate = DATE_Add_Duration($planneddate,$duration);
-               $wkno++;
-           }
-       }
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
-    }
-    if ($subscription->{periodicity} == 5) {
-my $duration=get_duration("1 months");
-       for(my $i = 0;$i < @irreg; $i++){
-           # warn $irreg[$i];
-           # warn $month;
-           if($month == 12) { $month = 0; } # need to rollover to check January
-           if($irreg[$i] == ($month+1)){ # check next one to see if is to be 
skipped
-               $planneddate = DATE_Add_Duration($planneddate,$duration);
-               $month++; # to check if following ones are to be skipped too
-           }
-       }
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
-    }
-    if ($subscription->{periodicity} == 6) {
-my $duration=get_duration("2 months");
-       for(my $i = 0;$i < @irreg; $i++){
-           # warn $irreg[$i];
-           # warn $month;
-           if($month == 12) { $month = 0; } # need to rollover to check January
-           if($irreg[$i] == ($month+1)){ # check next one to see if is to be 
skipped
-               $planneddate = DATE_Add_Duration($planneddate,$duration);
-               $month++; # to check if following ones are to be skipped too
-           }
-       }
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
-    }
-    if ($subscription->{periodicity} == 7 || $subscription->{periodicity} == 8 
) {
-my $duration=get_duration("3 months");
-       for(my $i = 0;$i < @irreg; $i++){
-           # warn $irreg[$i];
-           # warn $month;
-           if($month == 12) { $month = 0; } # need to rollover to check January
-           if($irreg[$i] == ($month+1)){ # check next one to see if is to be 
skipped
-               $planneddate = DATE_Add_Duration($planneddate,$duration);
-               $month++; # to check if following ones are to be skipped too
-           }
-       }
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
-    }
-
-    if ($subscription->{periodicity} == 9) {
-my $duration=get_duration("6 months");
-       for(my $i = 0;$i < @irreg; $i++){
-           # warn $irreg[$i];
-           # warn $month;
-           if($month == 12) { $month = 0; } # need to rollover to check January
-           if($irreg[$i] == ($month+1)){ # check next one to see if is to be 
skipped
-               $planneddate = DATE_Add_Duration($planneddate,$duration);
-               $month++; # to check if following ones are to be skipped too
-           }
-       }
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
-    }
-    if ($subscription->{periodicity} == 10) {
-my $duration=get_duration("1 years");
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
-    }
-    if ($subscription->{periodicity} == 11) {
-       my $duration=get_duration("2 years");
-       $resultdate=DATE_Add_Duration($planneddate,$duration);
+    if ( $subscription->{periodicity} == 11 ) {
+        @resultdate = Add_Delta_YM($year,$month, $day, 2, 0 );
     }
-    #    warn "date: ".$resultdate;
-    return $resultdate;
+    my 
$resultdate=sprintf("%04d-%02d-%02d",$resultdate[0],$resultdate[1],$resultdate[2]);
+#     warn "dateNEXTSEQ : ".$resultdate;
+    return "$resultdate";
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]