Created
July 11, 2010 13:02
-
-
Save esad/471525 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.join(File.dirname(__FILE__),'spec_helper') | |
def parse(str) | |
Timespan.parse(str).map {|span| [span.day_of_week,span.from_h,span.from_m,span.to_h,span.to_m] } | |
end | |
mon,tue,wed,thu,fri,sat,sun = 1,2,3,4,5,6,7 | |
describe Timespan do | |
it 'parses single day/single hourspan' do | |
t = [17,0,18,30] | |
parse("Mo 17:00-18:30").should.equal [[mon,*t]] | |
parse("Sonntag: 17:00-18:30").should.equal [[sun,*t]] | |
parse("Fr.: 17:00:00-18:30:00").should.equal [[fri,*t]] | |
end | |
it 'parses day spans/single hourspan' do | |
t = [17,0,18,30] | |
['Mo-Mi 17:00-18:30','Mo-Mi 17.00-18.30','Mo.-Mi. 17:00-18.30'].each do |str| | |
parse(str).should.equal [[mon,*t],[tue,*t], [wed,*t]] | |
end | |
end | |
it 'parses multiple days/multiple hourspans' do | |
t1,t2 = [8,0,12,0], [13,0,15,0] | |
parse('Mo,Di 08:00-12:00,13:00-15:00').should.equal [[mon,*t1],[mon,*t2],[tue,*t1],[tue,*t2]] | |
end | |
it 'parses multiple days with different hourspans' do | |
parse('Mo 08:00-19:00, Di 08:00-18:00').should.equal [[mon,8,0,19,0],[tue,8,0,18,0]] | |
end | |
it 'parses multiple dayspans with different hourspans' do | |
t1,t2 = [8,0,19,0],[8,0,17,0] | |
parse('Mo-Do 08:00-19:00, Fr 08:00-17:00').should.equal [[mon,*t1],[tue,*t1],[wed,*t1],[thu,*t1],[fri,*t2]] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment