Skip to content

Commit

Permalink
Default ZoTime to ENV['TZ'], gh-220
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
jmettraux committed Nov 13, 2016
1 parent c58e9c4 commit 5153857
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 100 deletions.
9 changes: 4 additions & 5 deletions lib/rufus/scheduler/cronline.rb
Expand Up @@ -58,8 +58,7 @@ def initialize(line)

items = line.split

#@timezone = items.pop if ZoTime.is_timezone?(items.last)
if tz = ZoTime.get_tzone(item.last)
if tz = ZoTime.get_tzone(items.last)
@timezone = tz.name
@original_timezone = items.pop
end
Expand Down Expand Up @@ -89,7 +88,7 @@ def initialize(line)
#
def matches?(time)

time = ZoTime.new(time.to_f, @timezone || ENV['TZ']).time
time = ZoTime.new(time.to_f, @timezone).time

return false unless sub_match?(time, :sec, @seconds)
return false unless sub_match?(time, :min, @minutes)
Expand Down Expand Up @@ -128,7 +127,7 @@ def matches?(time)
def next_time(from=Time.now)

time = nil
zotime = ZoTime.new(from.to_i + 1, @timezone || ENV['TZ'])
zotime = ZoTime.new(from.to_i + 1, @timezone)

loop do

Expand Down Expand Up @@ -163,7 +162,7 @@ def next_time(from=Time.now)
def previous_time(from=Time.now)

time = nil
zotime = ZoTime.new(from.to_i - 1, @timezone || ENV['TZ'])
zotime = ZoTime.new(from.to_i - 1, @timezone)

loop do

Expand Down
21 changes: 1 addition & 20 deletions lib/rufus/scheduler/zotime.rb
Expand Up @@ -22,7 +22,6 @@
# Made in Japan.
#++

#require 'rufus/scheduler/zones'
require 'tzinfo'


Expand All @@ -39,7 +38,7 @@ class ZoTime
def initialize(s, zone)

@seconds = s.to_f
@zone = self.class.get_tzone(zone)
@zone = self.class.get_tzone(zone || ENV['TZ'])

fail ArgumentError.new(
"cannot determine timezone from #{zone.inspect}"
Expand Down Expand Up @@ -98,24 +97,6 @@ def -(t)
end
end

# def add(t, sign=1)
#
# if t.is_a?(Numeric)
# @seconds += sign * t
# self
# elsif t.respond_to?(:to_f)
# @seconds += sign * t.to_f
# else
# fail ArgumentError.new(
# "cannot #{sign == 1 ? 'add' : 'substract'} #{t.class} " +
# "instance to ZoTime instance")
# end
# end
# alias :+ add
#
# def substract(t); add(t, -1); end
# alias :- substract

def self.parse(str, opts={})

if defined?(::Chronic) && t = ::Chronic.parse(str, opts)
Expand Down
75 changes: 0 additions & 75 deletions spec/zotime_spec.rb
Expand Up @@ -37,81 +37,6 @@
end
end

# describe '.envtzable?' do
#
# def etza?(s); Rufus::Scheduler::ZoTime.envtzable?(s); end
#
# it 'matches' do
#
# expect(etza?('Asia/Tokyo')).to eq(true)
# expect(etza?('America/Los_Angeles')).to eq(true)
# expect(etza?('Europe/Paris')).to eq(true)
# expect(etza?('UTC')).to eq(true)
#
# expect(etza?('Japan')).to eq(true)
# expect(etza?('Turkey')).to eq(true)
# end
#
# it 'does not match' do
#
# expect(etza?('14:00')).to eq(false)
# expect(etza?('14:00:14')).to eq(false)
# expect(etza?('2014/12/11')).to eq(false)
# expect(etza?('2014-12-11')).to eq(false)
# expect(etza?('+25:00')).to eq(false)
#
# expect(etza?('+09:00')).to eq(false)
# expect(etza?('-01:30')).to eq(false)
# expect(etza?('-0200')).to eq(false)
#
# expect(etza?('Wed')).to eq(false)
# expect(etza?('Sun')).to eq(false)
# expect(etza?('Nov')).to eq(false)
#
# expect(etza?('PST')).to eq(false)
# expect(etza?('Z')).to eq(false)
#
# expect(etza?('YTC')).to eq(false)
# expect(etza?('Asia/Paris')).to eq(false)
# expect(etza?('Nada/Nada')).to eq(false)
# end
#
# #it 'returns true for all entries in the tzinfo list' do
# # File.readlines(
# # File.join(File.dirname(__FILE__), '../misc/tz_all.txt')
# # ).each do |tz|
# # tz = tz.strip
# # if tz.length > 0 && tz.match(/^[^#]/)
# # p tz
# # expect(llat?(tz)).to eq(true)
# # end
# # end
# #end
# end

describe '.is_timezone?' do

def is_timezone?(o); Rufus::Scheduler::ZoTime.is_timezone?(o); end

it 'returns true when passed a string describing a timezone' do
end

it 'returns false when it cannot make sense of the timezone' do
end

#it 'returns true for all entries in the tzinfo list' do
# File.readlines(
# File.join(File.dirname(__FILE__), '../misc/tz_all.txt')
# ).each do |tz|
# tz = tz.strip
# if tz.length > 0 && tz.match(/^[^#]/)
# #p tz
# expect(is_timezone?(tz)).to eq(true)
# end
# end
#end
end

describe '.parse' do

it 'parses a time string without a timezone' do
Expand Down

0 comments on commit 5153857

Please sign in to comment.