1package Olson::Abbreviations; 2use strict; 3use warnings; 4 5use Moose; 6 7use MooseX::ClassAttribute; 8use namespace::autoclean; 9 10our $VERSION = '0.04'; 11 12class_has 'ZONEMAP' => ( 13 isa => 'HashRef[Maybe[Str]]' 14 , is => 'rw' 15 , traits => ['Hash'] 16 , handles => { 17 '_exists' => 'exists' 18 , '_get' => 'get' 19 , '_defined' => 'defined' 20 } 21 , default => sub { 22 # Table for mapping abbreviated timezone names to tz_abbreviations 23 return { 24 'A' => '+0100', 'ACDT' => '+1030', 'ACST' => '+0930', 25 'ADT' => undef, 'AEDT' => '+1100', 'AES' => '+1000', 26 'AEST' => '+1000', 'AFT' => '+0430', 'AHDT' => '-0900', 27 'AHST' => '-1000', 'AKDT' => '-0800', 'AKST' => '-0900', 28 'AMST' => '+0400', 'AMT' => '+0400', 'ANAST' => '+1300', 29 'ANAT' => '+1200', 'ART' => '-0300', 'AST' => undef, 30 'AT' => '-0100', 'AWST' => '+0800', 'AZOST' => '+0000', 31 'AZOT' => '-0100', 'AZST' => '+0500', 'AZT' => '+0400', 32 'B' => '+0200', 'BADT' => '+0400', 'BAT' => '+0600', 33 'BDST' => '+0200', 'BDT' => '+0600', 'BET' => '-1100', 34 'BNT' => '+0800', 'BORT' => '+0800', 'BOT' => '-0400', 35 'BRA' => '-0300', 'BST' => undef, 'BT' => undef, 36 'BTT' => '+0600', 'C' => '+0300', 'CAST' => '+0930', 37 'CAT' => undef, 'CCT' => undef, 'CDT' => undef, 38 'CEST' => '+0200', 'CET' => '+0100', 'CETDST' => '+0200', 39 'CHADT' => '+1345', 'CHAST' => '+1245', 'CKT' => '-1000', 40 'CLST' => '-0300', 'CLT' => '-0400', 'COT' => '-0500', 41 'CST' => undef, 'CSuT' => '+1030', 'CUT' => '+0000', 42 'CVT' => '-0100', 'CXT' => '+0700', 'ChST' => '+1000', 43 'D' => '+0400', 'DAVT' => '+0700', 'DDUT' => '+1000', 44 'DNT' => '+0100', 'DST' => '+0200', 'E' => '+0500', 45 'EASST' => '-0500', 'EAST' => undef, 'EAT' => '+0300', 46 'ECT' => undef, 'EDT' => undef, 'EEST' => '+0300', 47 'EET' => '+0200', 'EETDST' => '+0300', 'EGST' => '+0000', 48 'EGT' => '-0100', 'EMT' => '+0100', 'EST' => undef, 49 'ESuT' => '+1100', 'F' => '+0600', 'FDT' => undef, 50 'FJST' => '+1300', 'FJT' => '+1200', 'FKST' => '-0300', 51 'FKT' => '-0400', 'FST' => undef, 'FWT' => '+0100', 52 'G' => '+0700', 'GALT' => '-0600', 'GAMT' => '-0900', 53 'GEST' => '+0500', 'GET' => '+0400', 'GFT' => '-0300', 54 'GILT' => '+1200', 'GMT' => '+0000', 'GST' => undef, 55 'GT' => '+0000', 'GYT' => '-0400', 'GZ' => '+0000', 56 'H' => '+0800', 'HAA' => '-0300', 'HAC' => '-0500', 57 'HAE' => '-0400', 'HAP' => '-0700', 'HAR' => '-0600', 58 'HAT' => '-0230', 'HAY' => '-0800', 'HDT' => '-0930', 59 'HFE' => '+0200', 'HFH' => '+0100', 'HG' => '+0000', 60 'HKT' => '+0800', 'HL' => 'local', 'HNA' => '-0400', 61 'HNC' => '-0600', 'HNE' => '-0500', 'HNP' => '-0800', 62 'HNR' => '-0700', 'HNT' => '-0330', 'HNY' => '-0900', 63 'HOE' => '+0100', 'HST' => '-1000', 'I' => '+0900', 64 'ICT' => '+0700', 'IDLE' => '+1200', 'IDLW' => '-1200', 65 'IDT' => undef, 'IOT' => '+0500', 'IRDT' => '+0430', 66 'IRKST' => '+0900', 'IRKT' => '+0800', 'IRST' => '+0430', 67 'IRT' => '+0330', 'IST' => undef, 'IT' => '+0330', 68 'ITA' => '+0100', 'JAVT' => '+0700', 'JAYT' => '+0900', 69 'JST' => '+0900', 'JT' => '+0700', 'K' => '+1000', 70 'KDT' => '+1000', 'KGST' => '+0600', 'KGT' => '+0500', 71 'KOST' => '+1200', 'KRAST' => '+0800', 'KRAT' => '+0700', 72 'KST' => '+0900', 'L' => '+1100', 'LHDT' => '+1100', 73 'LHST' => '+1030', 'LIGT' => '+1000', 'LINT' => '+1400', 74 'LKT' => '+0600', 'LST' => 'local', 'LT' => 'local', 75 'M' => '+1200', 'MAGST' => '+1200', 'MAGT' => '+1100', 76 'MAL' => '+0800', 'MART' => '-0930', 'MAT' => '+0300', 77 'MAWT' => '+0600', 'MDT' => '-0600', 'MED' => '+0200', 78 'MEDST' => '+0200', 'MEST' => '+0200', 'MESZ' => '+0200', 79 'MET' => undef, 'MEWT' => '+0100', 'MEX' => '-0600', 80 'MEZ' => '+0100', 'MHT' => '+1200', 'MMT' => '+0630', 81 'MPT' => '+1000', 'MSD' => '+0400', 'MSK' => '+0300', 82 'MSKS' => '+0400', 'MST' => '-0700', 'MT' => '+0830', 83 'MUT' => '+0400', 'MVT' => '+0500', 'MYT' => '+0800', 84 'N' => '-0100', 'NCT' => '+1100', 'NDT' => '-0230', 85 'NFT' => undef, 'NOR' => '+0100', 'NOVST' => '+0700', 86 'NOVT' => '+0600', 'NPT' => '+0545', 'NRT' => '+1200', 87 'NST' => undef, 'NSUT' => '+0630', 'NT' => '-1100', 88 'NUT' => '-1100', 'NZDT' => '+1300', 'NZST' => '+1200', 89 'NZT' => '+1200', 'O' => '-0200', 'OESZ' => '+0300', 90 'OEZ' => '+0200', 'OMSST' => '+0700', 'OMST' => '+0600', 91 'OZ' => 'local', 'P' => '-0300', 'PDT' => '-0700', 92 'PET' => '-0500', 'PETST' => '+1300', 'PETT' => '+1200', 93 'PGT' => '+1000', 'PHOT' => '+1300', 'PHT' => '+0800', 94 'PKT' => '+0500', 'PMDT' => '-0200', 'PMT' => '-0300', 95 'PNT' => '-0830', 'PONT' => '+1100', 'PST' => '-0800', 96 'PWT' => '+0900', 'PYST' => '-0300', 'PYT' => '-0400', 97 'Q' => '-0400', 'R' => '-0500', 'R1T' => '+0200', 98 'R2T' => '+0300', 'RET' => '+0400', 'ROK' => '+0900', 99 'S' => '-0600', 'SADT' => '+1030', 'SAST' => undef, 100 'SBT' => '+1100', 'SCT' => '+0400', 'SET' => '+0100', 101 'SGT' => '+0800', 'SRT' => '-0300', 'SST' => undef, 102 'SWT' => '+0100', 'T' => '-0700', 'TFT' => '+0500', 103 'THA' => '+0700', 'THAT' => '-1000', 'TJT' => '+0500', 104 'TKT' => '-1000', 'TMT' => '+0500', 'TOT' => '+1300', 105 'TRUT' => '+1000', 'TST' => '+0300', 'TUC' => '+0000', 106 'TVT' => '+1200', 'U' => '-0800', 'ULAST' => '+0900', 107 'ULAT' => '+0800', 'USZ1' => '+0200', 'USZ1S' => '+0300', 108 'USZ3' => '+0400', 'USZ3S' => '+0500', 'USZ4' => '+0500', 109 'USZ4S' => '+0600', 'USZ5' => '+0600', 'USZ5S' => '+0700', 110 'USZ6' => '+0700', 'USZ6S' => '+0800', 'USZ7' => '+0800', 111 'USZ7S' => '+0900', 'USZ8' => '+0900', 'USZ8S' => '+1000', 112 'USZ9' => '+1000', 'USZ9S' => '+1100', 'UTZ' => '-0300', 113 'UYT' => '-0300', 'UZ10' => '+1100', 'UZ10S' => '+1200', 114 'UZ11' => '+1200', 'UZ11S' => '+1300', 'UZ12' => '+1200', 115 'UZ12S' => '+1300', 'UZT' => '+0500', 'V' => '-0900', 116 'VET' => '-0400', 'VLAST' => '+1100', 'VLAT' => '+1000', 117 'VTZ' => '-0200', 'VUT' => '+1100', 'W' => '-1000', 118 'WAKT' => '+1200', 'WAST' => undef, 'WAT' => '+0100', 119 'WEST' => '+0100', 'WESZ' => '+0100', 'WET' => '+0000', 120 'WETDST' => '+0100', 'WEZ' => '+0000', 'WFT' => '+1200', 121 'WGST' => '-0200', 'WGT' => '-0300', 'WIB' => '+0700', 122 'WIT' => '+0900', 'WITA' => '+0800', 'WST' => undef, 123 'WTZ' => '-0100', 'WUT' => '+0100', 'X' => '-1100', 124 'Y' => '-1200', 'YAKST' => '+1000', 'YAKT' => '+0900', 125 'YAPT' => '+1000', 'YDT' => '-0800', 'YEKST' => '+0600', 126 'YEKT' => '+0500', 'YST' => '-0900', 'Z' => '+0000', 127 } 128 } 129); 130 131has 'tz_abbreviation' => ( isa => 'Str', is => 'rw', required => 1 ); 132 133sub is_known { 134 my $self = shift; 135 $self->_exists( $self->tz_abbreviation ); 136} 137 138sub is_unambigious { 139 my $self = shift; 140 $self->_defined( $self->tz_abbreviation ); 141} 142 143sub get_offset { 144 my $self = shift; 145 146 Carp::croak 'Unknown abreviation please submit ' 147 . $self->tz_abbreviation 148 . ' to : http://rt.cpan.org/NoAuth/Bugs.html?Dist=Olson-Abbreviations' 149 unless $self->is_known 150 ; 151 152 Carp::croak "Globally ambigious abbreviation detected" 153 unless $self->is_unambigious; 154 ; 155 156 $self->_get( $self->tz_abbreviation ); 157} 158 159__PACKAGE__->meta->make_immutable; 160 1611; 162 163__END__ 164 165=head1 NAME 166 167Olson::Abbreviations -globally unique timezones abbreviation handling 168 169=head1 DESCRIPTION 170 171This module should help you with converting commonly used and often ambigious olson 172abbreviations into TZ offset notation. 173 174=head2 NOT COMPLETE 175 176This module is released as 0.01 because it is useful. It is not complete. In order to 177be complete in the author's eyes this module must accept a locale and disambiguate based 178on that. 179 180EST is not ambigious if your standing in the US or in Austrailia. This module should 181handle this properly in the future. 182 183=head1 SYNOPSIS 184 185Quick summary of what the module does. 186 187Perhaps a little code snippet. 188 189 use Olson::Abbreviations; 190 191 my $oa = Olson::Abbreviations->new({ tz_abbreviation => 'EST' }); 192 $oa->is_unambigious; # returns 0 193 $oa->is_known; # returns 1 194 $oa->get_offset # dies 195 ... 196 197=head1 METHODS 198 199=over 12 200 201=item get_offset 202 203Returns the offset to UTC 204 205=item is_unambigious 206 207Returns 0|1 based on if the abbreviation is globally unambigious to the whole planet 208 209=item is_known 210 211Returns 0|1 based on if the abbreviation is known despite if it is ambigious or not 212 213=back 214 215=head1 AUTHOR 216 217Evan Carroll, C<< <me+cpan at evancarroll.com> >> 218 219=head1 BUGS 220 221Please report any bugs or feature requests to C<bug-olson-abbreviations at rt.cpan.org>, or through 222the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Olson-Abbreviations>. I will be notified, and then you'll 223automatically be notified of progress on your bug as I make changes. 224 225=head1 SUPPORT 226 227You can find documentation for this module with the perldoc command. 228 229 perldoc Olson::Abbreviations 230 231 232You can also look for information at: 233 234=over 4 235 236=item * RT: CPAN's request tracker 237 238L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Olson-Abbreviations> 239 240=item * AnnoCPAN: Annotated CPAN documentation 241 242L<http://annocpan.org/dist/Olson-Abbreviations> 243 244=item * CPAN Ratings 245 246L<http://cpanratings.perl.org/d/Olson-Abbreviations> 247 248=item * Search CPAN 249 250L<http://search.cpan.org/dist/Olson-Abbreviations/> 251 252=back 253 254=head1 COPYRIGHT & LICENSE 255 256Copyright 2012 Evan Carroll, all rights reserved. 257 258This program is free software; you can redistribute it and/or modify it 259under the same terms as Perl itself. 260 261 262=cut 263 2641; # End of Olson::Abbreviations 265