From 4b7b03f8a1802e27520603f76bd40bd5090fd7f1 Mon Sep 17 00:00:00 2001 From: Lars Haugseth Date: Sat, 3 Oct 2015 16:34:27 +0200 Subject: [PATCH] Convert TimeOfDay values to UTC. --- lib/crono/period.rb | 2 +- lib/crono/time_of_day.rb | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/crono/period.rb b/lib/crono/period.rb index 75c3309..3c7a436 100644 --- a/lib/crono/period.rb +++ b/lib/crono/period.rb @@ -31,7 +31,7 @@ module Crono def description desc = "every #{@period.inspect}" - desc += " between #{@interval.from} and #{@interval.to}" if @interval + desc += " between #{@interval.from} and #{@interval.to} UTC" if @interval desc += format(' at %.2i:%.2i', @at_hour, @at_min) if @at_hour && @at_min desc += " on #{DAYS[@on].capitalize}" if @on desc diff --git a/lib/crono/time_of_day.rb b/lib/crono/time_of_day.rb index 3244bbc..63c541d 100644 --- a/lib/crono/time_of_day.rb +++ b/lib/crono/time_of_day.rb @@ -6,17 +6,15 @@ module Crono attr_accessor :hour, :min def self.parse(value) - case value - when String - time = Time.parse(value) - new time.hour, time.min - when Hash - new value[:hour], value[:min] - when Time - new value.hour, value.min - else - fail "Unknown TimeOfDay format: #{value.inspect}" - end + time = + case value + when String then Time.parse(value).utc + when Hash then Time.now.change(value).utc + when Time then value.utc + else + fail "Unknown TimeOfDay format: #{value.inspect}" + end + new time.hour, time.min end def initialize(hour, min)