Ignore:
Timestamp:
2011-06-01T12:33:42+12:00 (13 years ago)
Author:
sjm84
Message:

Updating the ExifTool perl modules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cpan/Image/ExifTool/Shift.pl

    r16842 r24107  
    1515#------------------------------------------------------------------------------
    1616# apply shift to value in new value hash
    17 # Inputs: 0) shift type, 1) shift string, 2) value to shift, 3) new value hash ref
     17# Inputs: 0) shift type, 1) shift string, 2) raw date/time value, 3) new value hash ref
    1818# Returns: error string or undef on success and updates value in new value hash
    1919sub ApplyShift($$$;$)
    2020{
    21     my ($func, $shift, $val, $newValueHash) = @_;
     21    my ($func, $shift, $val, $nvHash) = @_;
    2222
    2323    # get shift direction from first character in shift string
     
    2525    my $pre = $1;
    2626    my $dir = ($pre eq '+') ? 1 : -1;
    27     my $tagInfo = $$newValueHash{TagInfo};
     27    my $tagInfo = $$nvHash{TagInfo};
    2828    my $tag = $$tagInfo{Name};
    29     my $self = $$newValueHash{Self};    # (used in eval)
     29    my $self = $$nvHash{Self};    # (used in eval)
    3030    my $shiftOffset;
    31     if ($$newValueHash{ShiftOffset}) {
    32         $shiftOffset = $$newValueHash{ShiftOffset};
     31    if ($$nvHash{ShiftOffset}) {
     32        $shiftOffset = $$nvHash{ShiftOffset};
    3333    } else {
    34         $shiftOffset = $$newValueHash{ShiftOffset} = { };
     34        $shiftOffset = $$nvHash{ShiftOffset} = { };
    3535    }
    3636
     
    6363    }
    6464    # update value in new value hash
    65     $newValueHash->{Value} = [ $val ];
     65    $nvHash->{Value} = [ $val ];
    6666    return undef;   # success
    6767}
     
    105105
    106106#------------------------------------------------------------------------------
    107 # split times into corresponding components: YYYY MM DD hh mm ss tzh tzm
     107# split times into corresponding components: YYYY mm dd HH MM SS tzh tzm
    108108# Inputs: 0) date/time or shift string 1) reference to list for returned components
    109109#         2) optional reference to list of time components (if shift string)
     
    152152            # this is a time (can't come after timezone)
    153153            (defined $v[3] or defined $v[6] or @vals > 3) and $err = 1, last;
    154             not $time and @vals != 3 and $err = 1, last;
     154            not $time and @vals != 3 and @vals != 2 and $err = 1, last;
    155155            $v[3] = shift(@vals);   # take hour first if only one specified
    156156            $v[4] = shift(@vals) || 0;
     
    175175#         2) shift direction, 3) reference to output list of shifted components
    176176#         4) number of decimal points in seconds
     177#         5) reference to return time difference due to rounding
    177178# Returns: error string or undef on success
    178 sub ShiftComponents($$$$$)
     179sub ShiftComponents($$$$$;$)
    179180{
    180     my ($time, $shift, $dir, $toTime, $dec) = @_;
     181    my ($time, $shift, $dir, $toTime, $dec, $rndPt) = @_;
    181182    # min/max for Y, M, D, h, m, s
    182183    my @min = (    0, 1, 1, 0, 0, 0);
     
    203204    if (defined $sec and $sec != int($sec)) {
    204205        my $mult = 10 ** $dec;
    205         $$toTime[5] = int($sec * $mult + 0.5 * ($sec <=> 0)) / $mult;
     206        my $rndSec = int($sec * $mult + 0.5 * ($sec <=> 0)) / $mult;
     207        $rndPt and $$rndPt = $sec - $rndSec;
     208        $$toTime[5] = $rndSec;
    206209    }
    207210#
     
    303306            $time[6] = $time[7] = 0 if $val =~ s/Z$/\+00:00/;
    304307        }
    305         my $err = ShiftComponents(\@time, \@shift, $dir, \@toTime, $dec);
     308        my $rndDiff;
     309        my $err = ShiftComponents(\@time, \@shift, $dir, \@toTime, $dec, \$rndDiff);
    306310        $err and return $err;
    307311#
     
    324328                    # handle fractional seconds separately
    325329                    $diff = $tm2[0] - int($tm2[0]) - ($tm1[0] - int($tm1[0]));
     330                    $diff += $rndDiff if defined $rndDiff;  # un-do rounding
    326331                    $tm1[0] = int($tm1[0]);
    327332                    $tm2[0] = int($tm2[0]);
     
    376381            $tm += $$shiftOffset{$mode};    # apply the shift
    377382            $tm < 0 and return 'Shift results in negative time';
    378             # strip off fractional seconds after rounding to desired precision
    379             # (only round if the result isn't integral)
     383            # save fractional seconds in shifted time
    380384            $frac = $tm - int($tm);
    381385            if ($frac) {
    382                 # round off to required number of decimal points
    383                 my $tmf = $tm + 0.5 * 10 ** (-$dec);
    384                 $tm = int($tmf);
    385                 $frac = $tm - $tmf;
     386                $tm = int($tm);
     387                # must account for any rounding that could occur
     388                $frac + 0.5 * 10 ** (-$dec) >= 1 and ++$tm, $frac = 0;
    386389            }
    387390            @tm = gmtime($tm);
     
    491494    '2:0'       - shift 2 hours (time, date/time), or 2 months (date)
    492495    '5:0:0'     - shift 5 hours (time, date/time), or 5 years (date)
    493     '0:0:1'     - shift 1 sec (time, date/time), or 1 day (date)
     496    '0:0:1'     - shift 1 s (time, date/time), or 1 day (date)
    494497
    495498If two arguments are given, the date shift is first, followed by the time
     
    561564philosophy).
    562565
     566=head1 BUGS
     567
     568This feature uses the standard time library functions, which typically are
     569limited to dates in the range 1970 to 2038.
     570
    563571=head1 AUTHOR
    564572
    565 Copyright 2003-2007, Phil Harvey (phil at owl.phy.queensu.ca)
     573Copyright 2003-2011, Phil Harvey (phil at owl.phy.queensu.ca)
    566574
    567575This library is free software; you can redistribute it and/or modify it
Note: See TracChangeset for help on using the changeset viewer.