Skip to content

Commit

Permalink
Merge branch 'adding-seconds' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain Barnett committed Oct 13, 2015
2 parents b2fea13 + 3c07623 commit 2778e1a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/ext/date_and_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def bump(attr, amount=nil)
Date.civil(self.year, self.month+amount, self.day)
when :year then
Date.civil(self.year + amount, self.month, self.day)
when :sec then
Date.civil(self.year, self.month, self.day, self.hour, self.minute, self.sec + amount)
else
raise Exception, "type \"#{attr}\" not supported."
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tickle/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.guess(tokens, start)


def self.guess_unit_types( tokens, start)
[:day,:week,:month,:year].find {|unit|
[:sec,:day,:week,:month,:year].each {|unit|
if Token.types(tokens).same?([unit])
throw :guessed, start.bump(unit)
end
Expand Down Expand Up @@ -60,7 +60,7 @@ def self.guess_month_names( tokens, start)

def self.guess_number_and_unit( tokens, start)
_next =
[:day,:week,:month,:year].each {|unit|
[:sec,:day,:week,:month,:year].each {|unit|
if Token.types(tokens).same?([:number, unit])
throw :guessed, start.bump( unit, Token.token_of_type(:number,tokens).interval )
end
Expand Down
7 changes: 6 additions & 1 deletion lib/tickle/repeater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def scan_for_numbers(token)

SCAN_FOR_ORDINAL_NAMES = {
/first/ => Ordinal.new( '1st' ),
/second/ => Ordinal.new( '2nd' ),
/second\b/ => Ordinal.new( '2nd' ),
/third/ => Ordinal.new( '3rd' ),
/fourth/ => Ordinal.new( '4th' ),
/fifth/ => Ordinal.new( '5th' ),
Expand Down Expand Up @@ -235,6 +235,11 @@ def scan_for_units(token)
:interval => 1,
:start => :today
},
/^sec(?:onds)?$/ => {
:type => :sec,
:interval => 1,
:start => :today
},
}

detection token, scanner do |md,key,value|
Expand Down
32 changes: 26 additions & 6 deletions spec/tickle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ module Tickle # for convenience

context "Simple examples", :frozen => true do

context "second" do
subject{ Tickle.parse('second') }
let(:expected) { {:next=>Time.parse("2010-05-09 20:57:37 +0000"), :expression=>"second", :starting=>Time.parse("2010-05-09 20:57:36 +0000"), :until=>nil} }
xit { should == expected }
# Can't use second as it clashes with date ordinal names
context "seconds" do
subject{ Tickle.parse('seconds') }
let(:expected) { {:next=>Time.parse("2010-05-09 20:57:37 +0000"), :expression=>"seconds", :starting=>Time.parse("2010-05-09 20:57:36 +0000"), :until=>nil} }
it { should == expected }
end

# Other variant for seconds
context "sec" do
subject{ Tickle.parse('sec') }
let(:expected) { {:next=>Time.parse("2010-05-09 20:57:37 +0000"), :expression=>"sec", :starting=>Time.parse("2010-05-09 20:57:36 +0000"), :until=>nil} }
it { should == expected }
end

context "minute" do
Expand Down Expand Up @@ -97,7 +105,13 @@ module Tickle # for convenience
context "3 seconds" do
subject{ Tickle.parse('3 seconds') }
let(:expected) { {:next=>Time.parse("2010-05-09 20:57:39 +0000"), :expression=>"3 seconds", :starting=>Time.parse("2010-05-09 20:57:36 +0000"), :until=>nil} }
xit { should == expected }
it { should == expected }
end

context "3 sec" do
subject{ Tickle.parse('3 sec') }
let(:expected) { {:next=>Time.parse("2010-05-09 20:57:39 +0000"), :expression=>"3 sec", :starting=>Time.parse("2010-05-09 20:57:36 +0000"), :until=>nil} }
it { should == expected }
end

context "3 minutes" do
Expand Down Expand Up @@ -136,7 +150,13 @@ module Tickle # for convenience
it { should == expected }
end

context "other second" do
context "other seconds" do
subject{ Tickle.parse('other second') }
let(:expected) { {:next=>Time.parse("2010-05-09 20:57:38 +0000"), :expression=>"other second", :starting=>Time.parse("2010-05-09 20:57:36 +0000"), :until=>nil} }
xit { should == expected }
end

context "other sec" do
subject{ Tickle.parse('other second') }
let(:expected) { {:next=>Time.parse("2010-05-09 20:57:38 +0000"), :expression=>"other second", :starting=>Time.parse("2010-05-09 20:57:36 +0000"), :until=>nil} }
xit { should == expected }
Expand Down

0 comments on commit 2778e1a

Please sign in to comment.