# ColorTime.pm
#
# returns a color asscoiated with the given time
# all colors are in standard:
#   00FF00 format
#
# Steve Pomeroy <steve@staticfree.info>
#######################################

use strict;
use ColorFunc;

package ColorTime;

use vars qw( $VERSION @EXPORT );

#@EXPORT  = qw( &colorClock );
$VERSION = (qw( $Revision: 0.1 $ ))[1];

{
    #no strict;
    $VERSION = '0.10';
}


# hard-coded colors paired with the number of minutes in the day
my %times=(
       '0'=>'00007f',
       '144'=>'000000',
       '432'=>'ff0000',
       '720'=>'ffff00', #yellow
       '1008'=>'00ff00',
       '1296'=>'0000ff',
       '1440'=>'00007f'
);


sub colorClock{ # time
  my ($time) = @_;
  my ($sec,$min,$hour) = localtime($time);
  my $mins = $min + $hour * 60;

  my $ppercent = ($mins-getLowTime($mins))/(getHighTime($mins)-getLowTime($mins));
  my $bgcolor = ColorFunc::calcFade($times{getLowTime($mins)}, $times{getHighTime($mins)}, $ppercent);

  return $bgcolor;
}

sub getLowTime{ #time in minutes
  (my $intime) = @_;
  my $min;
  foreach my $colortime (keys %times){
    if($colortime <= $intime){
      if($min <= $colortime){$min = $colortime}
    }
  }
  return $min;
}
sub getHighTime{ #time in minutes
  (my $intime)=@_;
  my($max)=1440;
  foreach my $colortime (keys %times){
    if($colortime > $intime){
      if($max > $colortime){$max = $colortime;}
    }
  }
  return $max;
}
