2 # various julian date calculations
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
14 use vars qw($VERSION $BRANCH @days @ldays @month);
15 main::mkver($VERSION = q$Revision$) if main->can('mkver');
17 @days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
18 @ldays = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
19 @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
23 my ($pkg, $year, $thing) = @_;
24 return bless [$year, $thing], ref($pkg)||$pkg;
30 return $old->alloc(@$old);
36 return $a->[1] - $b->[1] if ($a->[0] == $b->[0]);
37 return $a->[0] - $b->[0];
59 return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) ? 1 : 0;
66 my ($year, $day) = (gmtime($t))[5,7];
68 return $pkg->SUPER::alloc($year, $day+1);
71 # take a julian date and subtract a number of days from it, returning the julian date
74 my ($old, $amount) = @_;
75 my $self = $old->copy;
76 my $diny = _isleap($self->[0]) ? 366 : 365;
77 $self->[1] -= $amount;
78 while ($self->[1] <= 0) {
80 $diny = _isleap($self->[0]) ? 366 : 365;
88 my ($old, $amount) = @_;
89 my $self = $old->copy;
90 my $diny = _isleap($self->[0]) ? 366 : 365;
91 $self->[1] += $amount;
92 while ($self->[1] > $diny) {
95 $diny = _isleap($self->[0]) ? 366 : 365;
103 my $days = $self->[1];
105 for (_isleap($self->[0]) ? @Julian::ldays : @Julian::days) {
113 return "$days-$Julian::month[$mon]-$self->[0]";
116 package Julian::Month;
125 my ($mon, $year) = (gmtime($t))[4,5];
127 return $pkg->SUPER::alloc($year, $mon+1);
130 # take a julian month and subtract a number of months from it, returning the julian month
133 my ($old, $amount) = @_;
134 my $self = $old->copy;
136 $self->[1] -= $amount;
137 while ($self->[1] <= 0) {
146 my ($old, $amount) = @_;
147 my $self = $old->copy;
149 $self->[1] += $amount;
150 while ($self->[1] > 12) {
160 return "$Julian::month[$self->[1]]-$self->[0]";