kepler has asked for the wisdom of the Perl Monks concerning the following question:

Hi, So I have a perl script where the user might or not have introduced a valid timezone name. My problem is to deal with that possibility without having to match with an array. Is there a simple way? I've tryed a simple comparison: if(my $tz = DateTime::TimeZone->new( name => $zone )){... then proceed. But guess what? 500 internal error... Cheers. JKepler

Replies are listed 'Best First'.
Re: Traping Time zone unexistent
by stevieb (Canon) on Dec 15, 2015 at 23:32 UTC

    Easiest way? Given you're stating 500 errors, this is a web app. Provide a drop-down list of valid timezones instead of a text field and all of your problems go away.

    If that's not feasible, populate a hash where the keys are valid zones, check for exists and spit an error if necessary (or build logic to guess... which I'd recommend against, unless, of course, a guess or a default is acceptable).

Re: Traping Time zone unexistent
by Anonymous Monk on Dec 15, 2015 at 23:52 UTC
      Hi, Many thanks :) DateTime::TimeZone->all_names made the trick. JKepler