Date-Manip

 view release on metacpan or  search on metacpan

lib/Date/Manip/TZ.pm  view on Meta::CPAN

               $off    = $dmb->_delta_convert('time',"0:0:$off");
               $off    = $dmb->_delta_convert('offset',$off);
               print "$off\n"  if ($debug);
               push(@zone,$off);
            }
         } else {
            print "undef\n"  if ($debug);
         }

      } elsif ($method eq 'file') {
         if (! @methods) {
            print "]\n"  if ($debug);
            carp "ERROR: [_set_curr_zone] file requires argument";
            return;
         }
         my $file = shift(@methods);
         print "$file] "  if ($debug);
         if (! -f $file) {
            print "not found\n"  if ($debug);
            next;
         }

         my $in = new IO::File;
         $in->open($file)  ||  next;
         my $firstline = 1;

         my @z;
         while (! $in->eof) {
            my $line = <$in>;
            chomp($line);
            next  if ($line =~ /^\s*\043/  ||
                      $line =~ /^\s*$/);
            if ($firstline) {
               $firstline = 0;
               $line      =~ s/^\s*//;
               $line      =~ s/\s*$//;
               $line      =~ s/["']//g;  # "
               $line      =~ s/\s+/_/g;
               @z         = ($line);
            }

            # We're looking for lines of the form:
            #   TZ = string
            #   TIMEZONE = string
            #   ZONE = string
            # Alternately, we may use a 1-line file (ignoring comments and
            # whitespace) which contains only the zone name (it may be
            # quoted or contain embedded whitespace).
            #
            # 'string' can be:
            #   the name of a timezone enclosed in single/double quotes
            #   with everything after the closing quote ignored (the
            #   name of the timezone may have spaces instead of underscores)
            #
            #   a space delimited list of tokens, the first of which
            #   is the time zone
            #
            #   the name of a timezone with underscores replaced by
            #   spaces and nothing after the timezone
            #
            # For some reason, RHEL6 desktop version stores timezones as
            #   America/New York
            # instead of
            #   America/New_York
            # which is why we have to handle the space/underscore
            # substitution.

            if ($line =~ /^\s*(?:TZ|TIMEZONE|ZONE)\s*=\s*(.*)\s*$/) {
               my $val  = $1;
               @z       = ();
               last  if (! $val);

               if ($val =~ /^(["'])(.*?)\1/) {
                  my $z = $2;
                  last  if (! $z);
                  $z    =~ s/\s+/_/g;
                  push(@zone,$z);

               } elsif ($val =~ /\s/) {
                  $val  =~ /^(\S+)/;
                  push(@zone,$1);
                  $val  =~ s/\s+/_/g;
                  push(@zone,$val);

               } else {
                  push(@zone,$val);
               }

               last;
            }
         }
         close(IN);

         push(@zone,@z)  if (@z);

         if ($debug) {
            if (@zone) {
               print "@zone\n";
            } else {
               print "no result\n";
            }
         }

      } elsif ($method eq 'tzdata') {
         if (@methods < 2) {
            print "]\n"  if ($debug);
            carp "ERROR: [_set_curr_zone] tzdata requires two arguments";
            return;
         }
         my $file    = shift(@methods);
         my $dir     = shift(@methods);
         print "$file $dir"  if ($debug);

         my $z;
         if (-f $file  &&  -d $dir) {
            $z = _get_zoneinfo_zone($file,$dir);
         }
 	 if (defined($z)) {
 	    push @zone, $z;
 	    print "] $z\n"  if ($debug);
 	 } elsif ($debug) {



( run in 2.042 seconds using v1.01-cache-2.11-cpan-2398b32b56e )