Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for stardate.pl

(view source code of stardate.pl as plain text)

  1. #! perl
  2.  
  3. if ( $ARGV[0] ) {
  4. 	print "\nStarDate.pl,  Version 1.00\n",
  5. 	      "Convert current day and time to stardate\n\n",
  6. 	      "Usage:  STARDATE.PL\n\n",
  7. 	      "Based on an algorithm found on The StarTrek Gallery\n",
  8. 	      "http://www.trainerscity.com/startrek/\n\n",
  9. 	      "Written by Rob van der Woude\n",
  10. 	      "http://www.robvanderwoude.com\n\n";
  11. }
  12.  
  13. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  14. $sY = $year - 423;
  15. # Is current year a leap year?
  16. if ( ( $year % 4 == 0 ) xor ( $year % 100 == 0 ) xor ( $year % 400 == 0 ) ) {
  17. 	$leapyear = 1;
  18. } else {
  19. 	$leapyear = 0;
  20. }
  21. $sX = int( 1000 * ( $yday + 1 ) / ( 365 + $leapyear ) );
  22. $sF = int( 0.5 + ( $min + 60 * $hour ) / 144 );
  23. $stardate = ( 1000 * $sY ) + $sX + ( $sF / 10 );
  24. print( "\nStardate is now $sY$sX.$sF\n" );
  25.  

page last uploaded: 2017-08-21, 14:26