Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Fix error if there is no matching time zone. Resolves #30.
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Dec 23, 2014
1 parent 324abc6 commit 35f2eda
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## 1.15 (2014-??-??)

* Removed broken distributed queries code.
* Previously if a time zone was not found, an undefined variable error would
be outputted. `get_time_zone` now returns `null` if there is no matching
time zone. (Fixed by justgoodman. GitHub #30.)

## 1.14 (2013-11-05)

Expand Down
8 changes: 8 additions & 0 deletions src/timezone.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?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) {
case "AD":
$timezone = "Europe/Andorra";
Expand Down
21 changes: 16 additions & 5 deletions timezone/make_time_zone_php_code.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@
use HTTP::Tiny;
use Text::CSV_XS;

my $old_country;
my $old_region;
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 "<?php\n";
print "function get_time_zone(\$country, \$region)\n{\n";
print " switch (\$country) {\n";
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});

Expand Down

0 comments on commit 35f2eda

Please sign in to comment.