Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add special casing of noon and midnight.

  • Loading branch information...
commit 6beefd9c1555fca292f3eaeb61e8de6ee8664e2d 1 parent 833a670
GlitchMr authored
Showing with 9 additions and 2 deletions.
  1. +5 −2 lib/DDG/Goodie/TimezoneConverter.pm
  2. +4 −0 t/TimezoneConverter.t
7 lib/DDG/Goodie/TimezoneConverter.pm
View
@@ -73,8 +73,11 @@ sub to_time {
= ( $hours - int $hours ) * 60 - sprintf( '%.4f', $seconds ) / 60;
my $seconds_format = int $seconds ? ':%02.0f' : "";
if ($american) {
+ # Special case certain hours
+ return 'midnight' if $hours == 0;
+ return 'noon' if $hours == 12;
$pm = ' A.M.';
- if ($hours >= 12) {
+ if ($hours > 12) {
$pm = ' P.M.';
$hours -= 12;
}
@@ -176,7 +179,7 @@ handle query => sub {
pop @output_timezones;
}
sprintf "%s ($input_format) is %s ($output_format).",
- $input_time, @input_timezones,
+ ucfirst $input_time, @input_timezones,
$output_time, @output_timezones;
};
4 t/TimezoneConverter.t
View
@@ -16,6 +16,10 @@ ddg_goodie_test(
test_zci('8:10 A.M. (AZOST, UTC-1) is 11:10 A.M. (CAT, UTC+2).'),
'1pm EDT into UTC+2' =>
test_zci('1:00 P.M. (EDT, UTC-4) is 7:00 P.M. (UTC+2).'),
+ '0pm into GMT' =>
+ test_zci('Noon (UTC) is noon (GMT).'),
+ '0am into UTC' =>
+ test_zci('Midnight (UTC) is midnight (UTC).'),
'1 into UTC -2 ' =>
test_zci('1:00 (UTC) is 23:00, 1 day prior (UTC-2).'),
' 1 into UTC-1' =>
Please sign in to comment.
Something went wrong with that request. Please try again.