Posted By

Scooter on 02/01/09


Tagged

fun Star Trek


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wizard04


Stardate


 / Published in: PHP
 

URL: http://reusablecode.blogspot.com/2009/01/stardate.html

Calculate the stardate in the 24th century Star Trek universe for a given Gregorian date in the real universe.

  1. <?php
  2. /*
  3.   Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
  4.  
  5.   This work is licensed under the Creative Commons Attribution License. To view
  6.   a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  7.   send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  8.   94305, USA.
  9.   */
  10.  
  11. // Returns the stardate for a given date.
  12. function stardate($timestamp)
  13. {
  14. $season = date("Y", $timestamp) - 1947;
  15. $episode = str_pad(round(1000 / 366 * (date("z", $timestamp) + 1)), 3, "0", STR_PAD_LEFT);
  16. $fractime = substr((date("g", $timestamp) * 60 + date("i", $timestamp)) / 144, 0, 1);
  17.  
  18. return $season . $episode . "." . $fractime;
  19. }
  20. ?>

Report this snippet  

You need to login to post a comment.