summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/time.rb
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2010-09-10 20:04:35 +0300
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2010-09-10 19:07:16 +0200
commit88b556954cf92a1feded2cd197bba53fb8c65e3d (patch)
treedcccdefa2ac9a20a79a3a1181b79374ec2616495 /data/rbot/plugins/time.rb
parenta194d08bf86c52de87187b9477045f024f1659dd (diff)
time: calibrate to user's timezone when parsing time input
Diffstat (limited to 'data/rbot/plugins/time.rb')
-rw-r--r--data/rbot/plugins/time.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/data/rbot/plugins/time.rb b/data/rbot/plugins/time.rb
index 5a1a579c..c89cf195 100644
--- a/data/rbot/plugins/time.rb
+++ b/data/rbot/plugins/time.rb
@@ -130,7 +130,13 @@ class TimePlugin < Plugin
begin
time = begin
- Time.parse str
+ if zone = @registry[m.sourcenick]
+ on_timezone(zone) {
+ Time.parse str
+ }
+ else
+ Time.parse str
+ end
rescue ArgumentError => e
# Handle 28/9/1978, which is a valid date representation at least in Italy
if e.message == 'argument out of range'
@@ -158,6 +164,13 @@ class TimePlugin < Plugin
:w => time >= now ? _("is") : _("was")
}
end
+
+ def on_timezone(to_zone)
+ original_zone = ENV["TZ"]
+ ENV["TZ"] = to_zone
+ return yield
+ ENV["TZ"] = original_zone
+ end
end
class ::Time