User Control Panel
Advertisements

HELP US, HELP YOU!

Precise Age Calculator

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Commands
View unanswered posts
Author Message
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Mon Mar 21, 2005 2:16 am    Post subject: Reply with quote

This command will calculate your age, down to the seconds (the more information given the more accurate it will be--based on GM time).

Example:
Quote:
Kirsle: !age 10-12-1987 7:32
ChaosTesting: You are 17 years, 7 months, 8 days, 18 hours, 42 minutes, and 32 seconds old (based on GM Time).


It uses Date::Calc - proving that Perl is just as capable of calculating large differences in time as PHP is.

Usage: !age -- [::]

Code:
Code:
#      .   .               <Leviathan><br />#     .:...::     Command Name // !age<br />#    .::   ::.     Description // Calculate your exact age.<br /># ..:;;. ' .;;:..        Usage // !age <month>-<day>-<year> [<hour>:<min>:<secs>]<br />#    .  '''  .     Permissions // Public<br />#     :;,:,;:         Listener // All<br />#     :     :        Copyright // 2005 AiChaos Inc.<br /><br />sub age {<br />     my ($self,$client,$msg) = @_;<br /><br />     if (length $msg == 0) {<br />          return "Age Calculator\n\n"<br />               . "Usage:\n"<br />               . "!age <lt>month<gt>-<lt>day<gt>-<lt>year<gt> [<lt>hour<gt>:<lt>min<gt>:<lt>secs<gt>]\n\n"<br />               . "Examples:\n"<br />               . "!age 10-12-1987\n"<br />               . "!age 9-18-2002\n"<br />               . "!age 4-12-1995 13:45\n"<br />               . "!age 1-1-2000 4:50:33";<br />     }<br /><br />     # Use Date-Calc to perform the calculation.<br />     use Date::Calc qw(Delta_YMDHMS);<br /><br />     # Array of months.<br />     my %mon = (<br />          jan => 1,<br />          feb => 2,<br />          mar => 3,<br />          apr => 4,<br />          may => 5,<br />          jun => 6,<br />          jul => 7,<br />          aug => 8,<br />          sep => 9,<br />          oct => 10,<br />          nov => 11,<br />          dec => 12,<br />     );<br /><br />     my $validMon = 0;<br /><br />     # Get data from the message.<br />     my ($date,$time) = split(/\s+/, $msg, 2);<br />     $time ||= '00:00:00';<br />     my ($hour,$min,$sec) = split(/:/, $time, 3);<br />     $hour ||= 0;<br />     $min  ||= 0;<br />     $sec  ||= 0;<br />     my ($month,$day,$year) = split(/\-/, $date, 3);<br />     if ($month !~ /[^0-9]/) {<br />          if ($month < 1 || $month > 12) {<br />               return "Invalid month range: goes from 1 to 12!";<br />          }<br />          $validMon = 1;<br />     }<br />     foreach my $abbrev (keys %mon) {<br />          if ($month =~ /^$abbrev/i) {<br />               $month = $mon{$abbrev};<br />               $validMon = 1;<br />               last;<br />          }<br />     }<br />     $month = ucfirst($month);<br /><br />     return "Invalid month! Give a number (1-12) or full name (i.e. October)!" unless $validMon;<br />     return "Invalid day of month! Give a number (1-31)!" unless $day !~ /[^0-9]/;<br />     if ($year =~ /[^0-9]/ || length $year != 4) {<br />          return "Invalid year! Give full four-number year (i.e. 1994)!";<br />     }<br /><br />     # Get the current date/time.<br />     my ($gsecs,$gmin,$ghour,$gmday,$gmon,$gyear,$gwday,$gyday,$gisdst) = gmtime();<br />     $gmon++;<br />     my $gday = $gmday;<br />     $gyear += 1900;<br /><br />     # Get the difference.<br />     print "\$year = $year; \$month = $month; \$day = $day\n"<br />          . "\t\$hour = $hour; \$min = $min; \$sec = $sec\n"<br />          . "\$gyear = $gyear; \$gmon = $gmon; \$gday = $gday\n"<br />          . "\t\t$ghour = $ghour; \$gmin = $gmin; \$gsecs = $gsecs\n";<br />     my ($dYear,$dMon,$dDay,$dHour,$dMin,$dSecs) =<br />          Delta_YMDHMS   ($year,$month,$day,  $hour,$min,$sec,<br />                    $gyear,$gmon,$gday, $ghour,$gmin,$gsecs) or return "Error: $!";<br /><br />     # Fix negative months.<br />     if ($dMon < 0) {<br />          $dYear--;<br />          $dMon = abs($dMon);<br />     }<br /><br />     return "You are $dYear years, $dMon months, $dDay days, $dHour hours, $dMin minutes, and $dSecs seconds old (based on GM Time).";<br />}<br />{<br />     Category    => 'Fun Stuff',<br />     Description => 'Calculate your exact age.',<br />     Usage       => '!age <month>-<day>-<year> [<hour>:<min>:<secs>]',<br />     Listener    => 'All',<br />};

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
M4RTIN
Member
Member


Joined: 31 Dec 2004
Posts: 134

Reputation: 19.2Reputation: 19.2

PostPosted: Mon Mar 21, 2005 6:38 am    Post subject: Reply with quote

Lol, Very good command, I like it alot.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Commands All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group