2 # various julian date calculations
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
14 use vars qw(@days @ldays @month);
15 @days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
16 @ldays = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
17 @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
21 my ($pkg, $year, $thing) = @_;
22 return bless [$year, $thing], ref($pkg)||$pkg;
28 return $old->alloc(@$old);
34 return $a->[1] - $b->[1] if ($a->[0] == $b->[0]);
35 return $a->[0] - $b->[0];
57 return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) ? 1 : 0;
64 my ($year, $day) = (gmtime($t))[5,7];
66 return $pkg->SUPER::alloc($year, $day+1);
69 # take a julian date and subtract a number of days from it, returning the julian date
72 my ($old, $amount) = @_;
73 my $self = $old->copy;
74 my $diny = _isleap($self->[0]) ? 366 : 365;
75 $self->[1] -= $amount;
76 while ($self->[1] <= 0) {
78 $diny = _isleap($self->[0]) ? 366 : 365;
86 my ($old, $amount) = @_;
87 my $self = $old->copy;
88 my $diny = _isleap($self->[0]) ? 366 : 365;
89 $self->[1] += $amount;
90 while ($self->[1] > $diny) {
93 $diny = _isleap($self->[0]) ? 366 : 365;
101 my $days = $self->[1];
103 for (_isleap($self->[0]) ? @Julian::ldays : @Julian::days) {
111 return "$days-$Julian::month[$mon]-$self->[0]";
114 package Julian::Month;
123 my ($mon, $year) = (gmtime($t))[4,5];
125 return $pkg->SUPER::alloc($year, $mon+1);
128 # take a julian month and subtract a number of months from it, returning the julian month
131 my ($old, $amount) = @_;
132 my $self = $old->copy;
134 $self->[1] -= $amount;
135 while ($self->[1] <= 0) {
144 my ($old, $amount) = @_;
145 my $self = $old->copy;
147 $self->[1] += $amount;
148 while ($self->[1] > 12) {
158 return "$Julian::month[$self->[1]]-$self->[0]";