TimezoneConverter: fixes #4210 fixed error in timezone display (#4262)

* fixed error in timezone display

* minor change

* added new test cases
master
Aastha 2017-06-15 02:08:18 +05:30 committed by Rob Emery
parent dc8876002e
commit 07bbf47634
2 changed files with 9 additions and 1 deletions

View File

@ -46,7 +46,10 @@ sub parse_timezone {
$minutes //= 0;
my $hour = int( $timezones{$name} / 100 );
$minutes += $timezones{$name} % 100;
# To avoid modulo of negative numbers
my $m = abs( $timezones{$name} ) % 100;
$m *= -1 if $timezones{$name} < 0;
$minutes += $m;
return ($timezone, $hour + $modifier + $minutes / 60);
}
@ -63,6 +66,7 @@ sub to_time {
}
my $minutes
= ( $hours - int $hours ) * 60 - sprintf( '%.4f', $seconds ) / 60;
my $seconds_format = int $seconds ? ':%02.0f' : "";
if ($american) {
# Special case certain hours
@ -132,6 +136,7 @@ handle query => sub {
for ( $input->{gmt_timezone}, $output->{gmt_timezone} ) {
$_ = to_time $_;
s/\A\b/+/;
s/:-\b/:/;
s/:00\z//;
}

View File

@ -50,6 +50,9 @@ ddg_goodie_test(
'11:22am est in utc' => build_test('4:22 PM UTC', '11:22 AM EST (UTC-5) to UTC'),
'1600 UTC in BST' => build_test('17:00 BST', '16:00 UTC to BST (UTC+1)'),
'12:00 GMT in PST' => build_test('4:00 PST', '12:00 GMT to PST (UTC-8)'),
'10:00PM EDT to NDT' => build_test('11:30 PM NDT', '10:00 PM EDT (UTC-4) to NDT (UTC-2:30)'),
'10:00AM MST to NST' => build_test('1:30 PM NST', '10:00 AM MST (UTC-7) to NST (UTC-3:30)'),
'1:40AM PDT to MIT' => build_test('11:10 PM MIT (1 day prior)', '1:40 AM PDT (UTC-7) to MIT (UTC-9:30)'),
# Intentional non-answers
'12 in binary' => undef,