aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2020-07-12 13:24:25 +1200
committerDavid Phillips <david@yeah.nah.nz>2020-07-12 13:24:25 +1200
commitb62c0da644f2000986b628f7a2e5b6faae8d53ba (patch)
treec565b8199baa52df3905163e8f649d3142a9e593
parent0a9d0532dd13a955e5adcd07be2d42ceeef2fa0c (diff)
downloadidalius-b62c0da644f2000986b628f7a2e5b6faae8d53ba.tar.xz
Timezone: Improve error messages for tz
-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);