aboutsummaryrefslogtreecommitdiff
path: root/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'Plugin')
-rw-r--r--Plugin/Timezone.pm17
1 files changed, 11 insertions, 6 deletions
diff --git a/Plugin/Timezone.pm b/Plugin/Timezone.pm
index 947bc7a..f3386b2 100644
--- a/Plugin/Timezone.pm
+++ b/Plugin/Timezone.pm
@@ -45,6 +45,10 @@ sub clock_message {
}
}
+sub make_unknown_zone_message {
+ return "I'm unsure what the time is for $_[0]";
+}
+
sub time {
my ($self, $irc, $logger, $who, $where, $ided, $rest, $no_reenter, @arguments) = @_;
@@ -62,16 +66,13 @@ sub time {
my $timestr = $d->strftime("%H:%M on %a %d %b, %Y (%Z)");
return clock_message($nick, $tz, $timestr);
} or do {
- return "$requester: I'm unsure what the time is for $nick";
+ return "$requester: ".make_unknown_zone_message $nick;
}
}
sub zone_convert {
my ($self, $irc, $logger, $who, $where, $ided, $rest, $no_reenter, @arguments) = @_;
- # tz 1200 from to
- # tz 1200 from
-
my $requester = (split /!/, $who)[0];
return "Syntax: tz <time> <from> [to]" unless @arguments == 2 || @arguments == 3;
@@ -86,13 +87,17 @@ sub zone_convert {
eval {
my $d = DateTime->now();
my $format = "%H:%M on %a %d %b, %Y (%Z)";
- $d->set_time_zone($from_tz);
+ eval {
+ $d->set_time_zone($from_tz);
+ } or return "$requester: ".make_unknown_zone_message $from_tz;
$d->set(
hour => $hour,
minute => $minute,
);
my $unconverted = $d->strftime($format);
- $d->set_time_zone($to_tz);
+ eval {
+ $d->set_time_zone($to_tz);
+ } or return "$requester: ".make_unknown_zone_message $to_tz;
my $converted = $d->strftime($format);
my $from_message = clock_message($from_arg, $from_tz, $unconverted);
my $to_message = clock_message($to_arg, $to_tz, $converted);