- my ($pkg, $fn, $year, $day, $mode) = @_;
-
- # if we are writing, check that the directory exists
- if (defined $mode) {
- my $dir = "$fn/$year";
- mkdir($dir, 0777) if ! -e $dir;
- }
- my $self = {};
- $self->{fn} = sprintf "$fn/$year/%03d.dat", $day;
- $mode = 'r' if !$mode;
- my $fh = new FileHandle $self->{fn}, $mode;
- return undef if !$fh;
- $fh->autoflush(1) if $mode ne 'r'; # make it autoflushing if writable
- $self->{fh} = $fh;
- $self->{year} = $year;
- $self->{day} = $day;
- dbg("julian", "opening $self->{fn}\n");
-
- return bless $self, $pkg;
+ my ($old, $amount) = @_;
+ my $self = $old->copy;
+ my $diny = _isleap($self->[0]) ? 366 : 365;
+ $self->[1] -= $amount;
+ while ($self->[1] <= 0) {
+ $self->[1] += $diny;
+ $self->[0] -= 1;
+ $diny = _isleap($self->[0]) ? 366 : 365;
+ }
+ return $self;