Fix MSK timezone and consolidate timezone lists.

master
cwallen 2015-07-19 04:43:36 +00:00
parent 96db068af5
commit a4ab113476
2 changed files with 11 additions and 37 deletions

View File

@ -5,6 +5,7 @@ use 5.010;
use strict;
use warnings;
use DDG::Goodie;
use DDG::GoodieRole::Dates;
use DateTime;
use POSIX qw(fmod);
@ -26,38 +27,7 @@ triggers any => qw(in into to);
zci is_cached => 1;
zci answer_type => 'timezone_converter';
my %timezones = qw(
ACDT 10.5 ACST 9.5 ACT 8 ADT -3 AEDT 11 AEST 10
AFT 4.5 AKDT -8 AKST -9 AMST 5 AMT 4 ART -3
AST -4 AWDT 9 AWST 8 AZOST -1 AZT 4 BDT 8
BIOT 6 BIT -12 BOT -4 BRT -3 BST 1 BTT 6
CAT 2 CCT 6.5 CDT -5 CEDT 2 CEST 2 CET 1
CHADT 13.75 CHAST 12.75 CHOT -8 CHST 10 CHUT 10 CIST -8
CIT 8 CKT -10 CLST -3 CLT -4 COST -4 COT -5
CST -6 CT 8 CVT -1 CWST 8.75 CXT 7 DAVT 7
DDUT 7 DFT 1 EASST -5 EAST -6 EAT 3 ECT -5
EDT -4 EEDT 3 EEST 3 EET 2 EGST 0 EGT -1
EIT 9 EST -5 FET 3 FJT 12 FKST -3 FKT -4
FNT -2 GALT -6 GAMT -9 GET 4 GFT -3 GILT 12
GIT -9 GMT 0 GST 4 GYT -4 HADT -9 HAEC 2
HAST -10 HKT 8 HMT 5 HOVT 7 HST -10 ICT 7
IDT 3 IOT 3 IRDT 8 IRKT 8 IRST 3.5 IST 5.5
JST 9 KGT 7 KOST 11 KRAT 7 KST 9 LHST 11
LINT 14 MAGT 12 MART -9.5 MAWT 5 MDT -6 MEST 2
MET 1 MHT 12 MIST 11 MIT -9.5 MMT 6.5 MSK 4
MST -7 MUT 4 MVT 5 MYT 8 NCT 11 NDT -2.5
NFT 11.5 NPT 5.75 NST -3.5 NT -3.5 NUT -11.5 NZDT 13
NZST 12 OMST 6 ORAT -5 PDT -7 PET -5 PETT 12
PGT 10 PHOT 13 PHT 8 PKT 5 PMDT 8 PMST 8
PONT 11 PST -8 RET 4 ROTT -3 SAKT 11 SAMT 4
SAST 2 SBT 11 SCT 4 SGT 8 SLT 5.5 SRT -3
SST -11 SYOT 3 TAHT -10 TFT 5 THA 7 TJT 5
TKT 14 TLT 9 TMT 5 TOT 13 TVT 12 UCT 0
ULAT 8 UTC 0 UYST -2 UYT -3 UZT 5 VET -4.5
VLAT 10 VOLT 4 VOST 6 VUT 11 WAKT 12 WAST 2
WAT 1 WEDT 1 WEST 1 WET 0 WST 8 YAKT 9
YEKT 5
);
my %timezones = %DDG::GoodieRole::Dates::tz_offsets;
my $default_tz = 'UTC';
my $localtime_re = qr/(?:(?:my|local|my local)\s*time(?:zone)?)/i;
@ -88,7 +58,10 @@ sub parse_timezone {
# Minutes can be skipped too
$minutes //= 0;
return ($timezone, $timezones{$name} + $modifier + $minutes / 60);
my $hour = int( $timezones{$name} / 100 );
$minutes += $timezones{$name} % 100;
return ($timezone, $hour + $modifier + $minutes / 60);
}
sub to_time {
@ -166,6 +139,7 @@ handle query => sub {
return unless defined($gmt_output_timezone);
my $modifier = $gmt_output_timezone - $gmt_input_timezone;
for ( $gmt_input_timezone, $gmt_output_timezone ) {
$_ = to_time $_;
s/\A\b/+/;
@ -198,11 +172,11 @@ handle query => sub {
my @output_timezones = ( $output_timezone, $gmt_output_timezone );
# I'm using @timezones because I need list context.
if ( !@timezones{ $input_timezone =~ /(\A\w+)/ } ) {
if ( @timezones{ $input_timezone =~ /(\A\w+)/ } !~ /[1-9]/ ) {
$input_format = '%s';
pop @input_timezones;
}
if ( !@timezones{ $output_timezone =~ /(\A\w+)/ } ) {
if ( @timezones{ $output_timezone =~ /(\A\w+)/ } !~ /[1-9]/ ) {
$output_format = '%s';
pop @output_timezones;
}

View File

@ -60,7 +60,7 @@ my $ambiguous_dates_matches = qr#^(?<m>$date_number)$date_delim(?<d>$date_number
my $number_suffixes = qr#(?:st|nd|rd|th)#i;
# Timezones: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
my %tz_offsets = (
our %tz_offsets = (
ACDT => '+1030',
ACST => '+0930',
ACT => '+0800',
@ -168,7 +168,7 @@ my %tz_offsets = (
MIST => '+1100',
MIT => '-0930',
MMT => '+0630',
MSK => '+0400',
MSK => '+0300',
MST => '-0700',
MUT => '+0400',
MVT => '+0500',