From 88b556954cf92a1feded2cd197bba53fb8c65e3d Mon Sep 17 00:00:00 2001 From: Raine Virta Date: Fri, 10 Sep 2010 20:04:35 +0300 Subject: time: calibrate to user's timezone when parsing time input --- data/rbot/plugins/time.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'data/rbot') 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 -- cgit v1.2.3