2 # various julian date calculations
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
14 use vars qw($VERSION $BRANCH @days @ldays @month);
15 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
16 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
17 $main::build += $VERSION;
18 $main::branch += $BRANCH;
20 @days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
21 @ldays = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
22 @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
26 my ($pkg, $year, $thing) = @_;
27 return bless [$year, $thing], ref($pkg)||$pkg;
33 return $old->alloc(@$old);
39 return $a->[1] - $b->[1] if ($a->[0] == $b->[0]);
40 return $a->[0] - $b->[0];
62 return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) ? 1 : 0;
69 my ($year, $day) = (gmtime($t))[5,7];
71 return $pkg->SUPER::alloc($year, $day+1);
74 # take a julian date and subtract a number of days from it, returning the julian date
77 my ($old, $amount) = @_;
78 my $self = $old->copy;
79 my $diny = _isleap($self->[0]) ? 366 : 365;
80 $self->[1] -= $amount;
81 while ($self->[1] <= 0) {
83 $diny = _isleap($self->[0]) ? 366 : 365;
91 my ($old, $amount) = @_;
92 my $self = $old->copy;
93 my $diny = _isleap($self->[0]) ? 366 : 365;
94 $self->[1] += $amount;
95 while ($self->[1] > $diny) {
98 $diny = _isleap($self->[0]) ? 366 : 365;
106 my $days = $self->[1];
108 for (_isleap($self->[0]) ? @Julian::ldays : @Julian::days) {
116 return "$days-$Julian::month[$mon]-$self->[0]";
119 package Julian::Month;
128 my ($mon, $year) = (gmtime($t))[4,5];
130 return $pkg->SUPER::alloc($year, $mon+1);
133 # take a julian month and subtract a number of months from it, returning the julian month
136 my ($old, $amount) = @_;
137 my $self = $old->copy;
139 $self->[1] -= $amount;
140 while ($self->[1] <= 0) {
149 my ($old, $amount) = @_;
150 my $self = $old->copy;
152 $self->[1] += $amount;
153 while ($self->[1] > 12) {
163 return "$Julian::month[$self->[1]]-$self->[0]";