
use Time::Local;
my $spy = 86400 * 365.2422;

prec("20061201");
prec("20061221");
for ("01" .. "07") {
  prec("2007${_}01");
}
prec("20070322");
prec("20070621");

sub len {
  my  $date = shift;
  my ($y, $m, $d) = unpack "A4 A2 A2", $date;
  my $time = timelocal(0,0,0,$d, $m-1, $y-1900);
  lensec($time);
}

sub lensec {
  720 - 160 * cos(($_[0] + 11*86400) * 2 * 3.1416 / $spy);
}

sub change {
  my  $date = shift;
  my ($y, $m, $d) = unpack "A4 A2 A2", $date;
  my $time = timelocal(0,0,0,$d, $m-1, $y-1900);
  my $time_tomorrow = $time + 86400;
  lensec($time_tomorrow) - lensec($time);
}

sub prec {
  my $date = shift;
  printf "%8s %7.3f\n", $date, change($date);
}
