From 2a9a151c64d07578728fdc42c84b9a9ea10974f6 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Fri, 5 Apr 2019 20:44:12 +1300 Subject: Timzone: Allow arbitrary timezone specification --- Plugin/Timezone.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Plugin/Timezone.pm b/Plugin/Timezone.pm index 6450a6d..6380465 100644 --- a/Plugin/Timezone.pm +++ b/Plugin/Timezone.pm @@ -30,14 +30,23 @@ sub time { return "Syntax: time [nick]" unless @arguments <= 1; my $nick = $arguments[0] || $requester; + my ($case_nick) = grep {/^$nick$/i} @known_zones; + my $tz; if ($case_nick) { + $tz = $config->{timezone}->{$case_nick}; + } else { + $tz = $nick; + } + + eval { my $d = DateTime->now(); - $d->set_time_zone($config->{timezone}->{$case_nick}); + $d->set_time_zone($tz); my $timestr = $d->strftime("%H:%M on %a %d %b, %Y (%Z)"); - return "$nick\'s clock reads $timestr"; - } else { - return "$requester: I don't know what timezone $nick is in"; + return "$nick\'s clock reads $timestr" if $case_nick; + return "Clocks in $tz read $timestr"; + } or do { + return "$requester: I'm unsure what the time is for $nick"; } } 1; -- cgit v1.1