Last active
March 9, 2017 19:15
-
-
Save aaronpk/bfdbd5430f11233b091fd3dbc5a3778b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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