zeroclickinfo-goodies/t/TimezoneConverter.t

130 lines
4.0 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;
zci answer_type => 'timezone_converter';
zci is_cached => 1;
2012-09-27 23:24:30 -07:00
my $test_location_tz = qr/\(E[DS]T, UTC-[45]\)/;
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' =>
2014-10-28 11:36:15 -07:00
test_zci('3:14 (UTC) is 3:14 (GMT).',
html => qr/.*3:14.*\(UTC\) is.*3:14.*\(GMT\)./
),
'8:10 AM AZOST into CAT' =>
test_zci('8:10 AM (AZOST, UTC-1) is 11:10 AM (CAT, UTC+2).',
html => '-ANY-'
),
2012-09-27 23:24:30 -07:00
'1pm EDT into UTC+2' =>
test_zci('1:00 PM (EDT, UTC-4) is 7:00 PM (UTC+2).',
html => '-ANY-'
),
'0pm into GMT' =>
test_zci('Noon (UTC) is noon (GMT).',
html => '-ANY-'
),
'0am into UTC' =>
test_zci('Midnight (UTC) is midnight (UTC).',
html => '-ANY-'
),
2012-09-27 23:24:30 -07:00
'1 into UTC -2 ' =>
test_zci('1:00 (UTC) is 23:00, 1 day prior (UTC-2).',
html => '-ANY-'
),
2012-09-27 23:24:30 -07:00
' 1 into UTC-1' =>
test_zci('1:00 (UTC) is 0:00 (UTC-1).',
html => '-ANY-'
),
2012-09-27 23:24:30 -07:00
'21 FNT into EET' =>
test_zci('21:00 (FNT, UTC-2) is 1:00, 1 day after (EET, UTC+2).',
html => '-ANY-'
),
2012-09-27 23:24:30 -07:00
'23:00:00 InTo UTC+1' =>
test_zci('23:00 (UTC) is 0:00, 1 day after (UTC+1).',
html => '-ANY-'
),
2012-09-27 23:24:30 -07:00
'23:00:01 Into UTC+1' =>
test_zci('23:00:01 (UTC) is 0:00:01, 1 day after (UTC+1).',
html => '-ANY-'
),
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) is 13:15 (UTC+0:30).',
html => '-ANY-'
),
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('19:42:42 (BIT, UTC-12) is 11:42:42, 5 days after (GMT+100).',
html => '-ANY-'
),
2012-09-27 23:24:30 -07:00
'19:42:42 CHADT into GMT-100' =>
test_zci('19:42:42 (CHADT, UTC+13:45) is 1:57:42, 4 days prior (GMT-100).',
html => '-ANY-'
),
2014-10-28 11:36:15 -07:00
'10:00AM MST to PST' =>
test_zci('10:00 AM (MST, UTC-7) is 9:00 AM (PST, UTC-8).',
html => '-ANY-'
),
2014-10-28 11:36:15 -07:00
'19:00 UTC to EST' =>
test_zci('19:00 (UTC) is 14:00 (EST, UTC-5).',
html => '-ANY-'
),
2014-10-28 11:36:15 -07:00
'1am UTC to PST' =>
test_zci('1:00 AM (UTC) is 5:00 PM, 1 day prior (PST, UTC-8).',
html => '-ANY-'
),
'12:40pm PST into JST' =>
test_zci('12:40 PM (PST, UTC-8) is 5:40 AM, 1 day after (JST, UTC+9).',
html => '-ANY-'
),
'12:40 pm from PST to JST' =>
test_zci('12:40 PM (PST, UTC-8) is 5:40 AM, 1 day after (JST, UTC+9).',
html => qr/.*12:40 PM.*\(PST, UTC-8\) is.*5:40 AM, 1 day after.*\(JST, UTC\+9\)./
),
'11:22am est in utc' =>
test_zci('11:22 AM (EST, UTC-5) is 4:22 PM (UTC).',
html => qr/.*11:22 AM.*\(EST, UTC-5\) is.*4:22 PM.*\(UTC\)./
),
# Location-specific tests (variable with DST)
'13:00 GMT in my time' =>
test_zci(qr/13:00 \(GMT\) is 9:00 $test_location_tz/,
html => '-ANY-'
),
'11:22am cest in my timezone' =>
test_zci(qr/11:22 AM \(CEST, UTC\+2\) is [54]:22 AM $test_location_tz/,
html => '-ANY-'
),
'11:22am cest in localtime' =>
test_zci(qr/11:22 AM \(CEST, UTC\+2\) is [54]:22 AM $test_location_tz/,
html => '-ANY-'
),
'11:22am cest in my local timezone' =>
test_zci(qr/11:22 AM \(CEST, UTC\+2\) is [54]:22 AM $test_location_tz/,
html => '-ANY-'
),
'12pm my time in CEST' =>
test_zci(qr/Noon $test_location_tz is [67]:00 PM \(CEST, UTC\+2\)./,
html => '-ANY-'
),
'12pm local timezone in CEST' =>
test_zci(qr/Noon $test_location_tz is [67]:00 PM \(CEST, UTC\+2\)./,
html => '-ANY-'
),
'12am my timezone in UTC' =>
test_zci(qr/Midnight $test_location_tz is [45]:00 AM \(UTC\)./,
html => '-ANY-'
),
'12am local time in UTC' =>
test_zci(qr/Midnight $test_location_tz is [45]:00 AM \(UTC\)./,
html => '-ANY-'
),
# Intentional non-answers
'12 in binary' => undef,
2012-09-27 23:24:30 -07:00
);
done_testing;