SunInfo: Implementing latitude & longitude

master
Rob Emery 2015-01-08 22:38:40 +00:00
parent 903c7cf610
commit 41a0512e59
2 changed files with 7 additions and 5 deletions

4
lib/DDG/Goodie/SunInfo.pm Normal file → Executable file
View File

@ -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,

8
t/SunInfo.t Normal file → Executable file
View File

@ -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,