Skip to content

Instantly share code, notes, and snippets.

@Ovid
Created January 24, 2018 15:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ovid/a28f15da01f5b69a55779e42e7046766 to your computer and use it in GitHub Desktop.
Save Ovid/a28f15da01f5b69a55779e42e7046766 to your computer and use it in GitHub Desktop.
GCT Clock
#!/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