Created
January 24, 2018 15:58
-
-
Save Ovid/a28f15da01f5b69a55779e42e7046766 to your computer and use it in GitHub Desktop.
GCT Clock
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
#!/usr/bin/env perl | |
# This program constantly prints the time in GCT (Galactic Coordinated Time) | |
# as used in the MMORPG Tau Station (https://taustation.space/) | |
# Obviously, we use something a bit more sophisticated than this :) | |
use strict; | |
use warnings; | |
use Time::HiRes 'sleep'; | |
$|++; # unbuffer STDOUT | |
use constant UNITS_PER_SEGMENT => 1000; | |
use constant SEGMENTS_PER_DAY => 100; | |
use constant UNITS_PER_DAY => UNITS_PER_SEGMENT * SEGMENTS_PER_DAY; | |
use constant DAYS_PER_CYCLE => 100; | |
use constant UNITS_PER_CYCLE => UNITS_PER_DAY * DAYS_PER_CYCLE; | |
use constant SECONDS_PER_UNIT => 0.864; | |
while (1) { | |
print "\r"; # clear the line | |
print gct(); | |
sleep SECONDS_PER_UNIT; | |
} | |
sub gct { | |
my $epoch = time; | |
$epoch += 187574400; | |
my $units = $epoch / SECONDS_PER_UNIT; | |
my $cycle = int( $units / UNITS_PER_CYCLE ); | |
$units -= $cycle * UNITS_PER_CYCLE; | |
my $day = int( $units / UNITS_PER_DAY ); | |
$units -= $day * UNITS_PER_DAY; | |
my $segment = int( $units / UNITS_PER_SEGMENT ); | |
$units -= $segment * UNITS_PER_SEGMENT; | |
my $unit = int($units); | |
return sprintf '%d.%02d/%02d:%03d GCT', $cycle, $day, $segment, $unit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment