#!/usr/bin/perl -w
#
# $Revision: 1.4 $ $Date: 2012-07-26 17:11:47-04 $
# $Source: /home/vogelke/bin/RCS/blood,v $
# $Host: sys7.com $
# $UUID: d3eaeeda-46ab-3e88-b79d-02978766bf56 $
#
#<blood: check ~/.bloodrc to see when I can donate again.
# The rc-file has unix time of next donation plus a message:
#          1146196800 You can give blood again after 2006-04-27

use strict;

my $file = $ENV{'HOME'} . "/.bloodrc";

open (my $fh, "< $file") or die "$file not found";
$_ = <$fh>;
close($fh);

my ($then, $human, @notes) = split;
my $now = time();
my $interval = int(($then - $now)/86400);
my $donate = "You can donate again after $human";

$_  = ($interval > 0)
      ? "$donate, in $interval days."
      : "$donate, today if you like.";

s/days/day/ if $interval == 1;

print "$_\n@notes\n";
exit(0);
