Skip to content
This repository was archived by the owner on Oct 15, 2022. It is now read-only.

Commit 2786874

Browse files
tossjmoollaza
authored andcommitted
Timezone Coverter: Removed friendly "Noon" and "Midnight" times from TimezoneConverter IA (#4481)
* Removed friendly "Noon" and "Midnight" times from TimezoneConverter IA * Add "Noon" and "Midnight" alongside numerical time
1 parent 4adee0f commit 2786874

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

lib/DDG/Goodie/TimezoneConverter.pm

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ sub to_time {
5959

6060
my $pm = "";
6161
my $seconds = 3600 * fmod $hours, 1 / 60;
62+
my $time_word = "";
6263

6364
# I'm using floating point numbers. They sometimes don't do what I want.
6465
if ( sprintf( '%.5f', $seconds ) == 60 ) {
@@ -69,16 +70,21 @@ sub to_time {
6970

7071
my $seconds_format = int $seconds ? ':%02.0f' : "";
7172
if ($american) {
72-
# Special case certain hours
73-
return 'midnight' if $hours == 0;
74-
return 'noon' if $hours == 12;
73+
if ($hours == 0) {
74+
$time_word = 'Midnight - ';
75+
} elsif ($hours == 12) {
76+
$time_word = 'Noon - ';
77+
}
78+
7579
$pm = ' AM';
76-
if ($hours > 12) {
80+
if ($hours >= 12) {
7781
$pm = ' PM';
7882
$hours -= 12 if (int($hours) > 12);
83+
} elsif ($hours == 0) {
84+
$hours = 12;
7985
}
8086
}
81-
sprintf "%i:%02.0f$seconds_format$pm", $hours, $minutes, $seconds;
87+
sprintf "$time_word%i:%02.0f$seconds_format$pm", $hours, $minutes, $seconds;
8288
}
8389

8490
handle query => sub {

t/TimezoneConverter.t

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ ddg_goodie_test(
3131
'3:14 UTC in GMT' => build_test('3:14 GMT', '3:14 UTC to GMT'),
3232
'8:10 AM AZOST into CAT' => build_test('11:10 AM CAT', '8:10 AM AZOST (UTC-1) to CAT (UTC+2)'),
3333
'1pm EDT into UTC+2' => build_test('7:00 PM UTC+2', '1:00 PM EDT (UTC-4) to UTC+2'),
34-
'0pm UTC into GMT' => build_test('Noon GMT', 'Noon UTC to GMT'),
35-
'0am UTC into UTC' => build_test('Midnight UTC', 'Midnight UTC to UTC'),
34+
'0pm UTC into GMT' => build_test('Noon - 12:00 PM GMT', 'Noon - 12:00 PM UTC to GMT'),
35+
'0am UTC into UTC' => build_test('Midnight - 12:00 AM UTC', 'Midnight - 12:00 AM UTC to UTC'),
3636
'1 UTC into UTC -2 ' => build_test('23:00 UTC-2 (1 day prior)', '1:00 UTC to UTC-2'),
3737
' 1 UTC into UTC-1' => build_test('0:00 UTC-1', '1:00 UTC to UTC-1'),
3838
'21 FNT into EET' => build_test('1:00 EET (1 day after)', '21:00 FNT (UTC-2) to EET (UTC+2)'),
@@ -71,12 +71,12 @@ ddg_goodie_test(
7171
'11:22am cest in localtime' => build_test(re(qr/5:22 AM EDT/), qq/11:22 AM CEST (UTC+2) to $test_location_tz/),
7272
'11:22am cest in my local timezone' => build_test(re(qr/5:22 AM EDT/), qq/11:22 AM CEST (UTC+2) to $test_location_tz/),
7373
'11:22am cest' => build_test(re(qr/5:22 AM EDT/), qq/11:22 AM CEST (UTC+2) to $test_location_tz/),
74-
'12pm my time in CEST' => build_test(q/6:00 PM CEST/, qq/Noon $test_location_tz to CEST (UTC+2)/),
75-
'12pm local timezone in CEST' => build_test(q/6:00 PM CEST/, qq/Noon $test_location_tz to CEST (UTC+2)/),
76-
'12pm in CEST' => build_test(q/6:00 PM CEST/, qq/Noon $test_location_tz to CEST (UTC+2)/),
77-
'12am my timezone in UTC' => build_test(q/4:00 AM UTC/, qq/Midnight $test_location_tz to UTC/),
78-
'12am local time in UTC' => build_test(q/4:00 AM UTC/, qq/Midnight $test_location_tz to UTC/),
79-
'12am in UTC' => build_test(q/4:00 AM UTC/, qq/Midnight $test_location_tz to UTC/)
74+
'12pm my time in CEST' => build_test(q/6:00 PM CEST/, qq/Noon - 12:00 PM $test_location_tz to CEST (UTC+2)/),
75+
'12pm local timezone in CEST' => build_test(q/6:00 PM CEST/, qq/Noon - 12:00 PM $test_location_tz to CEST (UTC+2)/),
76+
'12pm in CEST' => build_test(q/6:00 PM CEST/, qq/Noon - 12:00 PM $test_location_tz to CEST (UTC+2)/),
77+
'12am my timezone in UTC' => build_test(q/4:00 AM UTC/, qq/Midnight - 12:00 AM $test_location_tz to UTC/),
78+
'12am local time in UTC' => build_test(q/4:00 AM UTC/, qq/Midnight - 12:00 AM $test_location_tz to UTC/),
79+
'12am in UTC' => build_test(q/4:00 AM UTC/, qq/Midnight - 12:00 AM $test_location_tz to UTC/)
8080
);
8181
restore_time();
8282

@@ -91,12 +91,12 @@ ddg_goodie_test(
9191
'11:22am cest in localtime' => build_test(re(qr/4:22 AM EST/), qq/11:22 AM CEST (UTC+2) to $test_location_tz/),
9292
'11:22am cest in my local timezone' => build_test(q/4:22 AM EST/, qq/11:22 AM CEST (UTC+2) to $test_location_tz/),
9393
'11:22am cest' => build_test(q/4:22 AM EST/, qq/11:22 AM CEST (UTC+2) to $test_location_tz/),
94-
'12pm my time in CEST' => build_test(q/7:00 PM CEST/, qq/Noon $test_location_tz to CEST (UTC+2)/),
95-
'12pm local timezone in CEST' => build_test(q/7:00 PM CEST/, qq/Noon $test_location_tz to CEST (UTC+2)/),
96-
'12pm in CEST' => build_test(q/7:00 PM CEST/, qq/Noon $test_location_tz to CEST (UTC+2)/),
97-
'12am my timezone in UTC' => build_test(re(qr/5:00 AM UTC/), qq/Midnight $test_location_tz to UTC/),
98-
'12am local time in UTC' => build_test(re(qr/5:00 AM UTC/), qq/Midnight $test_location_tz to UTC/),
99-
'12am in UTC' => build_test(re(qr/5:00 AM UTC/), qq/Midnight $test_location_tz to UTC/),
94+
'12pm my time in CEST' => build_test(q/7:00 PM CEST/, qq/Noon - 12:00 PM $test_location_tz to CEST (UTC+2)/),
95+
'12pm local timezone in CEST' => build_test(q/7:00 PM CEST/, qq/Noon - 12:00 PM $test_location_tz to CEST (UTC+2)/),
96+
'12pm in CEST' => build_test(q/7:00 PM CEST/, qq/Noon - 12:00 PM $test_location_tz to CEST (UTC+2)/),
97+
'12am my timezone in UTC' => build_test(re(qr/5:00 AM UTC/), qq/Midnight - 12:00 AM $test_location_tz to UTC/),
98+
'12am local time in UTC' => build_test(re(qr/5:00 AM UTC/), qq/Midnight - 12:00 AM $test_location_tz to UTC/),
99+
'12am in UTC' => build_test(re(qr/5:00 AM UTC/), qq/Midnight - 12:00 AM $test_location_tz to UTC/),
100100
);
101101

102102
restore_time();

0 commit comments

Comments
 (0)