Permalink
Browse files

added tests for sm_sd, and commented out sm_sy

  • Loading branch information...
1 parent 5e14db0 commit bd9ff2d8336577f9e04ef7da25fe7bccfe9d5680 Lee Jarvis committed Aug 14, 2011
Showing with 22 additions and 12 deletions.
  1. +1 −1 lib/chronic/chronic.rb
  2. +4 −5 lib/chronic/handlers.rb
  3. +17 −6 test/test_parsing.rb
@@ -183,7 +183,7 @@ def definitions(options={})
Handler.new([:repeater_month_name, :scalar_year], :handle_rmn_sy),
Handler.new([:scalar_day, :repeater_month_name, :scalar_year, :separator_at?, 'time?'], :handle_sd_rmn_sy),
Handler.new([:scalar_year, :separator_slash_or_dash, :scalar_month, :separator_slash_or_dash, :scalar_day, :separator_at?, 'time?'], :handle_sy_sm_sd),
- Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_day], :handle_sd_sm),
+ Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_day], :handle_sm_sd),
Handler.new([:scalar_month, :separator_slash_or_dash, :scalar_year], :handle_sm_sy)
],
@@ -198,17 +198,16 @@ def handle_sy_sm_sd(tokens, options)
handle_sm_sd_sy(new_tokens + time_tokens, options)
end
- # Handle scalar-day/scalar-month
- def handle_sd_sm(tokens, options)
- day = tokens[1].get_tag(ScalarDay).type
+ # Handle scalar-day/scalar-month AND scalar-month/scalar-day
+ def handle_sm_sd(tokens, options)
month = tokens[0].get_tag(ScalarMonth).type
+ day = tokens[1].get_tag(ScalarDay).type
+ year = Chronic.now.year
if Array(options[:endian_precedence]).first == :little
day, month = month, day
end
- year = Chronic.now.year
-
return if month_overflow?(year, month, day)
begin
View
@@ -261,17 +261,28 @@ def test_handle_sy_sm_sd
assert_equal Time.local(1902, 8, 20, 12, 0, 0), time
end
- def test_handle_sm_sy
+ def test_handle_sm_sd
time = parse_now("05/06")
- assert_equal Time.local(2006, 5, 16, 12), time
+ assert_equal Time.local(2006, 5, 6, 12), time
- time = parse_now("12/06")
- assert_equal Time.local(2006, 12, 16, 12), time
+ time = parse_now("05/06", :endian_precedence => [:little, :medium])
+ assert_equal Time.local(2006, 6, 5, 12), time
- time = parse_now("13/06")
- assert_equal nil, time
+ time = parse_now("13/01")
+ assert_nil time
end
+ # def test_handle_sm_sy
+ # time = parse_now("05/06")
+ # assert_equal Time.local(2006, 5, 16, 12), time
+ #
+ # time = parse_now("12/06")
+ # assert_equal Time.local(2006, 12, 16, 12), time
+ #
+ # time = parse_now("13/06")
+ # assert_equal nil, time
+ # end
+
def test_handle_r
end

0 comments on commit bd9ff2d

Please sign in to comment.