File: vendor/geoip/geoip/timezone/make_time_zone_php_code.pl

Recommend this page to a friend!
  Classes of Ganesh Kandu  >  kchat  >  vendor/geoip/geoip/timezone/make_time_zone_php_code.pl  >  Download  
File: vendor/geoip/geoip/timezone/make_time_zone_php_code.pl
Role: Example script
Content type: text/plain
Description: Example script
Class: kchat
Database driven PHP live chat system
Author: By
Last change:
Date: 2 years ago
Size: 1,542 bytes
 

Contents

Class file image Download
#!/usr/bin/perl

use strict;
use warnings;

use HTTP::Tiny;
use Text::CSV_XS;

my $old_country = q{};
my $old_region = q{};

my $response = HTTP::Tiny->new->get(
    'http://dev.maxmind.com/static/csv/codes/time_zone.csv');

die "Failed to download CSV!\n" unless $response->{success};

print <<'EOF';
<?php

/**
 * Get time zone
 * @param string $country
 * @param string $region
 * @return string If the timezone is not found, returns null`
 */
function get_time_zone($country, $region)
{
   
$timezone = null;
    switch (
$country) {
EOF

my $csv
= Text::CSV_XS->new ({ binary => 1});

my @timezones = split /\n/, $response->{content};
shift @timezones;

for
my $line (@timezones) {
   
$csv->parse($line) or die $csv->error_diag();
   
my ( $country, $region, $timezone ) = $csv->fields;

    if (
$country ne $old_country ) {
        if (
$old_region ne q{} ) {
            print
" }\n";
            print
" break;\n";
        }
        print
' case "' . $country . q(") . ":\n";
        if (
$region ne q{} ) {
            print "
switch (\$region) {\n";
        }
    }
    if (
$region ne q{} ) {
        print ' case "' . $region . q(") . ":\n ";
    }
    print '
$timezone = "' . $timezone . q(") . ";\n";
    if (
$region ne q{} ) {
        print
" break;\n";
    }
    else {
        print
" break;\n";
    }
   
$old_country = $country;
   
$old_region = $region;
}
print
" }\n";
print
" return \$timezone;\n";

print
"}\n";



For more information send a message to info at phpclasses dot org.