Skip to content

Commit

Permalink
Merge pull request mojombo#212 from davispuh/patch-1
Browse files Browse the repository at this point in the history
Ruby 1.8 compatibility
  • Loading branch information
davispuh committed Sep 6, 2013
2 parents ace1c57 + b212b1c commit 7793dd6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/chronic.rb
Expand Up @@ -139,7 +139,7 @@ def self.construct(year, month = 1, day = 1, hour = 0, minute = 0, second = 0, o
end
if Chronic.time_class.name == "Date"
Chronic.time_class.new(year, month, day)
elsif not Chronic.time_class.respond_to?(:new)
elsif not Chronic.time_class.respond_to?(:new) or (RUBY_VERSION.to_f < 1.9 and Chronic.time_class.name == "Time")
Chronic.time_class.local(year, month, day, hour, minute, second)
else
offset = Time::normalize_offset(offset) if Chronic.time_class.name == "DateTime"
Expand Down
2 changes: 1 addition & 1 deletion lib/chronic/parser.rb
Expand Up @@ -90,7 +90,7 @@ def pre_normalize(text)
text = text.to_s.downcase
text.gsub!(/\b(\d{2})\.(\d{2})\.(\d{4})\b/, '\3 / \2 / \1')
text.gsub!(/\b([ap])\.m\.?/, '\1m')
text.gsub!(/(?<=:\d{2}|:\d{2}\.\d{3})\-(\d{2}:?\d{2})\b/, 'tzminus\1')
text.gsub!(/(\s+|:\d{2}|:\d{2}\.\d{3})\-(\d{2}:?\d{2})\b/, '\1tzminus\2')
text.gsub!(/\./, ':')
text.gsub!(/([ap]):m:?/, '\1m')
text.gsub!(/['"]/, '')
Expand Down
3 changes: 3 additions & 0 deletions test/test_parsing.rb
Expand Up @@ -180,6 +180,9 @@ def test_handle_sy_sm_sd_t_tz
time = parse_now("2011-07-03 22:11:35 +01:00")
assert_equal 1309727495, time.to_i

time = parse_now("2011-07-03 16:11:35 -05:00")
assert_equal 1309727495, time.to_i

time = parse_now("2011-07-03 21:11:35 UTC")
assert_equal 1309727495, time.to_i

Expand Down

0 comments on commit 7793dd6

Please sign in to comment.