From 41a0512e59569d6134a0b316af7f731913544812 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Thu, 8 Jan 2015 22:38:40 +0000 Subject: [PATCH] SunInfo: Implementing latitude & longitude --- lib/DDG/Goodie/SunInfo.pm | 4 +++- t/SunInfo.t | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) mode change 100644 => 100755 lib/DDG/Goodie/SunInfo.pm mode change 100644 => 100755 t/SunInfo.t diff --git a/lib/DDG/Goodie/SunInfo.pm b/lib/DDG/Goodie/SunInfo.pm old mode 100644 new mode 100755 index c30a21a79..a7d2da3b3 --- a/lib/DDG/Goodie/SunInfo.pm +++ b/lib/DDG/Goodie/SunInfo.pm @@ -62,11 +62,13 @@ handle remainder => sub { $dt = parse_datestring_to_date($+{'when'}) if($+{'when'}); return unless $dt; # Also going to need to know which day. - $dt->set_time_zone($tz); + $dt->set_time_zone($tz) unless ($+{'lat'} && $+{'lon'}); $lon = parse_arc($+{'lon'}) if ($+{'lon'}); $lat = parse_arc($+{'lat'}) if ($+{'lat'}); + $where = "coordinates ${lat}°N ${lon}°E" if($+{'lat'} && $+{'lon'}); + my $sun_at_loc = DateTime::Event::Sunrise->new( longitude => $lon, latitude => $lat, diff --git a/t/SunInfo.t b/t/SunInfo.t old mode 100644 new mode 100755 index 2cf8efbce..42f7e1bbd --- a/t/SunInfo.t +++ b/t/SunInfo.t @@ -30,10 +30,10 @@ ddg_goodie_test( 'sunset on 2015-01-01' => test_zci(@exact), 'what time is sunrise on 2015-01-01?' => test_zci(@exact), 'January 1st, 2015 sunrise' => test_zci(@exact), - q{sunrise at 39°57'N 75°10'W} => test_zci(""), - 'sunset at 53N 10E' => test_zci(""), - 'sunset at 53S 15W' => test_zci(""), - 'sunset at 53N 10E on 2014-01-01' => test_zci(""), + q{sunrise at 39°57'N 5°10'W} => test_zci(qr"On.*coordinates .*AM.*PM", html => '-ANY-'), + 'sunset at 1S 1W' => test_zci(qr"On .*, sunrise in coordinates -1°N -1°E is at .*AM; sunset at .*PM.", html => '-ANY-'), + 'sunset at 53N 2E on 2014-01-01' => test_zci("On 01 Jan 2014, sunrise in coordinates 53°N 2°E is at 8:05 AM; sunset at 3:46 PM.", html => '-ANY-'), + 'sunset at 53N 2W on 2014-01-08' => test_zci("On 08 Jan 2014, sunrise in coordinates 53°N -2°E is at 8:18 AM; sunset at 4:11 PM.", html => '-ANY-'), 'sunset for philly' => undef, 'sunrise on mars' => undef, 'sunset boulevard' => undef,