Package: mencal
Version: 2.3-5
Seems the patch I supplied before was rather buggy, so I've rewritten
it. The patch below works much better.
I'm a little confused why you created a new program rather than simply
patch mencal? If someone's only using one 'start' (or even no start
command), it works the same way it always did.
--- 2.3-5/mencal-2.3/debian/mencalnreg 2005-12-23 09:45:46.937783465 -0500
+++ ./mencalnreg 2005-12-23 11:20:40.742638212 -0500
@@ -194,46 +194,57 @@
}
}
+ sub getnext {
+ my $self = shift;
+ my $first = shift;
+ my $starts = $self->{'start'};
+ my $length = $self->{'length'} * 24 * 3600;
+ my $n_s = scalar @{$starts};
+ my $best;
+
+ if (($n_s > 0) && (date2sec($starts->[0]) <= $first) &&
+ ($first <= date2sec($starts->[($n_s - 1)]))) {
+ foreach (@{$starts}) {
+ $best = date2sec($_);
+ last if $best >= $first;
+ }
+ return $best;
+ }
+
+ if ($n_s == 0) {
+ $best = strftime "%Y%m%d", localtime;
+ } elsif ($first < date2sec($starts->[0])) {
+ $best = date2sec($starts->[0]);
+ } else {
+ $best = date2sec($starts->[$n_s - 1]);
+ }
+
+ while ($best > ($first + $length)) {
+ $best -= $length;
+ }
+
+ while ($best < $first) {
+ $best += $length;
+ }
+
+ return $best;
+ }
+
sub getdays {
my $self = shift;
my ($year, $month) = (shift, shift);
- my $starts = $self->{'start'};
my $duration = $self->{'duration'} * 24 * 3600;
- my $length = $self->{'length'} * 24 * 3600;
$self->{'days'} = '#';
my $month_first = mktime(0, 0, 0, 1, ($month-1), ($year-1900));
my $month_next = mktime(0, 0, 0, 1, $month, ($year-1900));
my $first_interesting = $month_first - $duration;
- if (scalar @{$starts} == 0) {
- push @{$starts},strftime "%Y%m%d", localtime;
- }
- my $j = 0;
- while (($first_interesting > date2sec($starts->[$j])) &&
- (($j + 1) < scalar @{$starts})) {
- $j++;
- }
-
- my $actday = date2sec($starts->[$j]);
-
- # extrapolate, if necessary.
- while ($actday >= $month_first) {
- $actday -= $length;
- }
- while (($actday + $length) < $month_first) {
- $actday += $length;
- }
+ my $actday = $self->getnext($first_interesting);
while ($actday < $month_next) {
markdays($self, $month_first, $month_next, $actday, $duration);
- if ((($j + 1) < scalar @{$starts}) &&
- ($actday >= date2sec($starts->[0]))) {
- $j++;
- $actday = date2sec($starts->[$j]);
- } else {
- $actday += $length;
- }
+ $actday = $self->getnext($actday + $duration + 1);
}
}
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]