X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FPA.pm;h=633d2fee5d9a41ea94a584843be521f56fe8df82;hb=035b1523b2136f620f1aa161b04c011a30fbc174;hp=2440feaffc747649557f4f7de524144d0cad0f6c;hpb=8492985c19c12b19d892a78664409590aeb57f47;p=NDIRC.git
diff --git a/Commands/PA.pm b/Commands/PA.pm
index 2440fea..633d2fe 100644
--- a/Commands/PA.pm
+++ b/Commands/PA.pm
@@ -21,6 +21,7 @@ package NDIRC::Commands::PA;
use strict;
use warnings;
+use feature ':5.10';
use Moose;
use MooseX::MethodAttributes;
@@ -81,4 +82,27 @@ FROM galaxies WHERE x = ? AND y = ? AND tick = (SELECT max(tick) from galaxies)
}
}
+sub time
+ : Help(syntax: .time [tick] [timezone] | Gives the time at the specied tick. Assumes GMT if no timezone is given and current tick if no tick is given.)
+{
+ my ($self, $c, $msg) = @_;
+ my ($tick,$timezone) = $msg =~ /^(\d+)?\s*(\S+)?$/ or die 'ARGS';
+
+ eval {
+ $tick //= $c->model->selectrow_array(q{SELECT tick()});
+ $timezone //= 'GMT';
+ my $query = $c->model->prepare(q{
+SELECT date_trunc('seconds',now() + (($1 - tick()) || ' hr')::interval) AT TIME ZONE $2
+ });
+ $query->execute($tick,$timezone);
+ my $time = $query->fetchrow_array;
+ $c->reply("Time at tick $tick, timezone $timezone: $time");
+ };
+ given ($@){
+ when(/time zone "(.+?)" not recognized/){
+ $c->reply("$1 is not a valid timezone.");
+ }
+ die $@ if $@;
+ }
+}
1;