From 4a612c2f7c2ec25ff55576c07438cfc3df032bbc Mon Sep 17 00:00:00 2001 From: Mitchell Perilstein Date: Sat, 29 Nov 2014 18:48:23 -0500 Subject: [PATCH] One-liner fix for issue #773 and new unit tests to exercise that area. --- lib/DDG/GoodieRole/Dates.pm | 3 +++ t/CalendarToday.t | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/DDG/GoodieRole/Dates.pm b/lib/DDG/GoodieRole/Dates.pm index 362d4ab8e..8d330a932 100755 --- a/lib/DDG/GoodieRole/Dates.pm +++ b/lib/DDG/GoodieRole/Dates.pm @@ -334,6 +334,9 @@ sub build_datestring_regex { ## Ambiguous, but potentially valid date formats push @regexes, $ambiguous_dates; + ## tomorrow, next week|month|year, ... etc + push @regexes, $relative_dates; + my $returned_regex = join '|', @regexes; return qr/$returned_regex/i; } diff --git a/t/CalendarToday.t b/t/CalendarToday.t index 4660c1691..3c4c2816c 100755 --- a/t/CalendarToday.t +++ b/t/CalendarToday.t @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; use DDG::Test::Goodie; +use Test::MockTime qw( :all ); zci answer_type => 'calendar'; zci is_cached => 0; @@ -81,5 +82,33 @@ S M T W T F S November 2009 "november's calendar" => test_zci(qr/\nS M T W T F S November [0-9]{4}\n.+/, html => '-ANY-'), ); +# Special focus on relative dates, examining the "today" circle +my $test_location_tz = qr/\(EDT, UTC-4\)/; +set_fixed_time("2014-06-11T09:45:56"); +ddg_goodie_test( + [qw( + DDG::Goodie::CalendarToday + )], + "calendar yesterday" => test_zci(qr/June 2014.*\|10\|/s, + html => qr#10#), + "calendar today" => test_zci(qr/June 2014.*\|11\|/s, + html => qr#11#), + "calendar tomorrow" => test_zci(qr/June 2014.*\|12\|/s, + html => qr#12#), + "calendar 20 days ago" => test_zci(qr/May 2014.*\|22\|/s, + html => qr#22#), + "calendar in 20 days" => test_zci(qr/July 2014.*\| 1\|/s, + html => qr#1#), + "calendar last week" => test_zci(qr/June 2014.*\| 4\|/s, + html => qr#4#), + "calendar next week" => test_zci(qr/June 2014.*\|18\|/s, + html => qr#18#), + "calendar last year" => test_zci(qr/June 2013.*\|11\|/s, + html => qr#11#), + "calendar next year" => test_zci(qr/June 2015.*\|11\|/s, + html => qr#11#), +); +restore_time(); + done_testing;