diff --git a/lib/time_sniffer.rb b/lib/time_sniffer.rb index 75e98da9..58ff0392 100644 --- a/lib/time_sniffer.rb +++ b/lib/time_sniffer.rb @@ -312,7 +312,7 @@ class TimeSniffer end DATE_SEPARATOR = /[-\/]/ - DATE_REGEX = /(\d{1,2})#{DATE_SEPARATOR}(\d{1,2})#{DATE_SEPARATOR}(\d{2,4})/ + DATE_REGEX = /((?:^|\s)\d{1,2})#{DATE_SEPARATOR}(\d{1,2})#{DATE_SEPARATOR}(\d{2,4})/ matcher(:date, DATE_REGEX) do |m| Parser.new(input, @context).parse_range diff --git a/spec/lib/time_sniffer_spec.rb b/spec/lib/time_sniffer_spec.rb index 1f81a0f4..5005c44f 100644 --- a/spec/lib/time_sniffer_spec.rb +++ b/spec/lib/time_sniffer_spec.rb @@ -208,4 +208,9 @@ describe TimeSniffer do it "should not find a time in random numbers and an emoji" do expect_parsed_as_nil("15😊00") end + + it "shouldnt match a date starting with the year" do + expect_parsed_as_nil("2020-03-27") + expect_parsed_as_nil("foo 2020-03-27") + end end