zeroclickinfo-goodies/t/TimezoneConverter.t

326 lines
10 KiB
Perl
Raw Normal View History

2012-09-27 23:24:30 -07:00
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use DDG::Test::Goodie;
use Test::MockTime qw( :all );
2012-09-27 23:24:30 -07:00
zci answer_type => 'timezone_converter';
zci is_cached => 1;
2012-09-27 23:24:30 -07:00
ddg_goodie_test(
['DDG::Goodie::TimezoneConverter'],
2012-09-28 01:17:20 -07:00
'3:14 in GMT' =>
test_zci('3:14 GMT',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['3:14 UTC to GMT'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '3:14 GMT',
2015-07-19 21:56:50 -07:00
},
),
'8:10 AM AZOST into CAT' =>
test_zci('11:10 AM CAT',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['8:10 AM AZOST (UTC-1) to CAT (UTC+2)'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '11:10 AM CAT',
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
'1pm EDT into UTC+2' =>
test_zci('7:00 PM UTC+2',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['1:00 PM EDT (UTC-4) to UTC+2'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '7:00 PM UTC+2',
2015-07-19 21:56:50 -07:00
},
),
'0pm into GMT' =>
test_zci('Noon GMT',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['Noon UTC to GMT'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => 'Noon GMT',
2015-07-19 21:56:50 -07:00
},
),
'0am into UTC' =>
test_zci('Midnight UTC',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['Midnight UTC to UTC'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => 'Midnight UTC',
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
'1 into UTC -2 ' =>
test_zci('23:00 UTC-2 (1 day prior)',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['1:00 UTC to UTC-2'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '23:00 UTC-2 (1 day prior)',
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
' 1 into UTC-1' =>
test_zci('0:00 UTC-1',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['1:00 UTC to UTC-1'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '0:00 UTC-1',
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
'21 FNT into EET' =>
test_zci('1:00 EET (1 day after)',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['21:00 FNT (UTC-2) to EET (UTC+2)'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '1:00 EET (1 day after)',
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
'23:00:00 InTo UTC+1' =>
test_zci('0:00 UTC+1 (1 day after)',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['23:00 UTC to UTC+1'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '0:00 UTC+1 (1 day after)',
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
'23:00:01 Into UTC+1' =>
test_zci('0:00:01 UTC+1 (1 day after)',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['23:00:01 UTC to UTC+1'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '0:00:01 UTC+1 (1 day after)',
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
'13:15:00 UTC-0:30 into UTC+0:30' =>
test_zci('13:15 UTC+0:30',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['13:15 UTC-0:30 to UTC+0:30'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '13:15 UTC+0:30',
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
# ok, this is unlikely to happen without trying to do that
'19:42:42 BIT into GMT+100' =>
test_zci('11:42:42 GMT+100 (5 days after)',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['19:42:42 BIT (UTC-12) to GMT+100'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '11:42:42 GMT+100 (5 days after)',
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
'19:42:42 CHADT into GMT-100' =>
test_zci('1:57:42 GMT-100 (4 days prior)',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['19:42:42 CHADT (UTC+13:45) to GMT-100'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '1:57:42 GMT-100 (4 days prior)',
2015-07-19 21:56:50 -07:00
},
),
2014-10-28 11:36:15 -07:00
'10:00AM MST to PST' =>
test_zci('9:00 AM PST',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['10:00 AM MST (UTC-7) to PST (UTC-8)'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '9:00 AM PST',
2015-07-19 21:56:50 -07:00
},
),
2014-10-28 11:36:15 -07:00
'19:00 UTC to EST' =>
test_zci('14:00 EST',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['19:00 UTC to EST (UTC-5)'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '14:00 EST',
2015-07-19 21:56:50 -07:00
},
),
2014-10-28 11:36:15 -07:00
'1am UTC to PST' =>
test_zci('5:00 PM PST (1 day prior)',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['1:00 AM UTC to PST (UTC-8)'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '5:00 PM PST (1 day prior)',
2015-07-19 21:56:50 -07:00
},
),
'12:40pm PST into JST' =>
test_zci('5:40 AM JST (1 day after)',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['12:40 PM PST (UTC-8) to JST (UTC+9)'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '5:40 AM JST (1 day after)',
2015-07-19 21:56:50 -07:00
},
),
'12:40 pm from PST to JST' =>
test_zci('5:40 AM JST (1 day after)',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['12:40 PM PST (UTC-8) to JST (UTC+9)'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '5:40 AM JST (1 day after)',
2015-07-19 21:56:50 -07:00
},
),
'11:22am est in utc' =>
test_zci('4:22 PM UTC',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['11:22 AM EST (UTC-5) to UTC'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '4:22 PM UTC',
2015-07-19 21:56:50 -07:00
},
),
'1600 UTC in BST' =>
test_zci('17:00 BST',
2015-07-19 21:56:50 -07:00
structured_answer => {
input => ['16:00 UTC to BST (UTC+1)'],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => '17:00 BST',
2015-07-19 21:56:50 -07:00
},
),
# Intentional non-answers
'12 in binary' => undef,
);
# Summertime
my $test_location_tz = q/EDT (UTC-4)/;
set_fixed_time("2014-10-14T00:00:00");
ddg_goodie_test(
['DDG::Goodie::TimezoneConverter'],
# Location-specific tests (variable with DST)
'13:00 GMT in my time' =>
test_zci(q/9:00 EDT/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/13:00 GMT to $test_location_tz/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/9:00 EDT/,
2015-07-19 21:56:50 -07:00
},
),
'11:22am cest in my timezone' =>
test_zci(qr/5:22 AM EDT/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => qr/5:22 AM EDT/,
2015-07-19 21:56:50 -07:00
},
),
'11:22am cest in localtime' =>
test_zci(qr/5:22 AM EDT/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => qr/5:22 AM EDT/,
2015-07-19 21:56:50 -07:00
},
),
'11:22am cest in my local timezone' =>
test_zci(qr/5:22 AM EDT/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => qr/5:22 AM EDT/,
2015-07-19 21:56:50 -07:00
},
),
'12pm my time in CEST' =>
test_zci(q/6:00 PM CEST/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/Noon $test_location_tz to CEST (UTC+2)/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/6:00 PM CEST/,
2015-07-19 21:56:50 -07:00
},
),
'12pm local timezone in CEST' =>
test_zci(q/6:00 PM CEST/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/Noon $test_location_tz to CEST (UTC+2)/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/6:00 PM CEST/,
2015-07-19 21:56:50 -07:00
},
),
'12am my timezone in UTC' =>
test_zci(q/4:00 AM UTC/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/Midnight $test_location_tz to UTC/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/4:00 AM UTC/,
2015-07-19 21:56:50 -07:00
},
),
'12am local time in UTC' =>
test_zci(q/4:00 AM UTC/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/Midnight $test_location_tz to UTC/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/4:00 AM UTC/,
2015-07-19 21:56:50 -07:00
},
),
);
restore_time();
set_fixed_time("2014-11-02T11:00:00");
$test_location_tz = 'EST (UTC-5)';
ddg_goodie_test(
['DDG::Goodie::TimezoneConverter'],
# Location-specific tests (variable with DST)
'13:00 GMT in my time' =>
test_zci(qq/8:00 EST/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/13:00 GMT to $test_location_tz/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/8:00 EST/,
2015-07-19 21:56:50 -07:00
},
),
'11:22am cest in my timezone' =>
test_zci(qr/4:22 AM EST/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => qr/4:22 AM EST/,
2015-07-19 21:56:50 -07:00
},
),
'11:22am cest in localtime' =>
test_zci(qr/4:22 AM EST/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => qr/4:22 AM EST/,
2015-07-19 21:56:50 -07:00
},
),
'11:22am cest in my local timezone' =>
test_zci(q/4:22 AM EST/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/11:22 AM CEST (UTC+2) to $test_location_tz/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/4:22 AM EST/,
2015-07-19 21:56:50 -07:00
},
),
'12pm my time in CEST' =>
test_zci(q/7:00 PM CEST/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/Noon $test_location_tz to CEST (UTC+2)/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/7:00 PM CEST/,
2015-07-19 21:56:50 -07:00
},
),
'12pm local timezone in CEST' =>
test_zci(q/7:00 PM CEST/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/Noon $test_location_tz to CEST (UTC+2)/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/7:00 PM CEST/,
2015-07-19 21:56:50 -07:00
},
),
'12am my timezone in UTC' =>
test_zci(qr/5:00 AM UTC/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/Midnight $test_location_tz to UTC/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/5:00 AM UTC/,
2015-07-19 21:56:50 -07:00
},
),
'12am local time in UTC' =>
test_zci(qr/5:00 AM UTC/,
2015-07-19 21:56:50 -07:00
structured_answer => {
input => [qq/Midnight $test_location_tz to UTC/],
2015-07-19 21:56:50 -07:00
operation => 'Convert Timezone',
result => q/5:00 AM UTC/,
2015-07-19 21:56:50 -07:00
},
),
2012-09-27 23:24:30 -07:00
);
restore_time();
2012-09-27 23:24:30 -07:00
done_testing;