I am making a script that should calculate one's age, and it uses Net::ICal::Time. For some odd reason, Net::ICal::Time doesn't accept any year under 1000. Then if you put the "human" year, localtime decides the user is somewhere around 105! How can this be fixed?
#!/usr/bin/perluse CGI;
print new CGI->header;
use Net::ICal::Time;
# Not yet implemented
$t = Net::ICal::Time->new(
second => 12,
minute => 5,
hour => 6,
day => 25,
month => 6,
year => 1992
);my $newtime=$t->as_localtime;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime((time-$newtime));print "According to our system, you are $year year(s) old.";
#
# add this after call to
# localtime because it returns
# current year minus 1900
#
$year = $year + 1900;
#
# I hate reading "You are 1 year(s) old..."
# so, since you are calculating a result
# that can be '1' or higher replace following
#
# print "According to our system, you are $year year(s) old.";
#
# with these two lines
#
$multip = 's'; if ($year == 1) { $multip = ''};
printf "According to our system, you are $year year%s old.", $multip;
#
#
#!/usr/bin/perluse CGI;
print new CGI->header;
use Net::ICal::Time;
# Not yet implemented
$t = Net::ICal::Time->new(
second => 12,
minute => 5,
hour => 6,
day => 25,
month => 6,
year => 1992
);my $newtime=$t->as_localtime;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime((time-$newtime));print "According to our system, you are ".($year-93)." year(s) old.";
and when you change it to the following, the year stays the same!
#!/usr/bin/perluse CGI;
print new CGI->header;
use Net::ICal::Time;
# Not yet implemented
$t = Net::ICal::Time->new(
second => 12,
minute => 5,
hour => 6,
day => 25,
month => 6,
year => 1990
);my $newtime=$t->as_localtime;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime((time-$newtime));print "According to our system, you are ".($year-93)." year(s) old.";