Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Last active March 9, 2017 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronpk/bfdbd5430f11233b091fd3dbc5a3778b to your computer and use it in GitHub Desktop.
Save aaronpk/bfdbd5430f11233b091fd3dbc5a3778b to your computer and use it in GitHub Desktop.
<?php
class Stardate {
# Ported from https://github.com/pioz/stardate/blob/master/lib/stardate.rb
private static $year_0 = 2323;
private static $year_duration = 365.2425;
public static function date_to_stardate($date) {
# days since the beginning of the year
$days = $date->format('z');
# seconds since the beginning of the day
$seconds = ((int)$date->format('G')*60*60) + ((int)$date->format('i')*60) + (int)$date->format('s');
return (($date->format('Y') - self::$year_0) + $days / self::$year_duration + $seconds / (self::$year_duration * 24 * 3600)) * 1000;
}
}
$date = new DateTime('2413-11-26 18:35:34 +0100');
echo Stardate::date_to_stardate($date)."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment