Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2.  
  3. /* - (string) tos_stardate
  4.  *
  5.  * Random 4-numbers (progressively higher throughout an episode), followed by a single decimal place representing time of day.
  6.  */
  7. function tos_stardate($timestamp = NULL) {
  8.     if(!$timestamp) $timestamp = time();
  9.     $hour = date('G', $timestamp);
  10.     $percent = intval($hour) / 24;
  11.     return mt_rand(1000,9999) . '.' . round($percent * 10);
  12. }
  13.  
  14. /* - (string) tng_stardate
  15.  *
  16.  * Century number - 20 followed by season number of show, followed by 3 random numbers (in progression throughout an episode),
  17.  * followed by a decimal and day of year.
  18.  */
  19. function tng_stardate($season = 1, $timestamp = NULL) {
  20.     if(!$timestamp) $timestamp = time();
  21.    
  22.     $century = intval(substr(date('Y', $timestamp), 0, 2)) + 1;
  23.     $century = $century - 20;
  24.    
  25.     return $century . $season . mt_rand(000, 999) . '.' . date('z', $timestamp);
  26. }
  27.  
  28. /* - (string) new_stardate
  29.  *
  30.  * Easy: year, decimal, day-of-year
  31.  */
  32. function new_stardate($timestamp = NULL) {
  33.     if(!$timestamp) $timestamp = time();
  34.    
  35.     return date('Y.z', $timestamp);
  36. }
  37.  
  38. echo 'The Original Series: ' . tos_stardate() . '<br />'
  39.      . 'The Next Generation: ' . tng_stardate(4) . '<br />'
  40.      . 'New Star Trek: ' . new_stardate();
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement