#------------------------------------------------------------------------------
# File:         local_time.config
#
# Description:  Determine local time based on GPS location and GPSDateTime
#
# Notes:        1. Requires that the API TimeZone option functions properly
#                  using an IANA time zone name (like "America/New_York"), so
#                  this may not work on Windows systems.
#
#               2. Time is based on GPSDateTime preferentially, otherwise
#                  DateTimeOriginal then CreateDate assuming the system time
#                  zone unless the corresponding OffsetTime tag exists.
#
# Usage:        exiftool -config local_time.config -localtime FILE
#
# Requires:     ExifTool version 12.78 or later
#
# Revisions:    2025-10-19 - P. Harvey Created
#------------------------------------------------------------------------------

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        LocalTime => {
            Groups => { 2 => 'Time' },
            Require => {
                0 => 'GPSLatitude',
                1 => 'GPSLongitude',
            },
            Desire => {
                2 => 'GPSDateTime',
                3 => 'SubSecDateTimeOriginal',
                4 => 'SubSecCreateDate',
                5 => 'DateTimeOriginal',
                6 => 'CreateDate',
            },
            ValueConv => q{
                require Image::ExifTool::Geolocation;
                my ($loc) = Image::ExifTool::Geolocation::Geolocate("$val[0],$val[1]");
                return undef unless $loc;
                my $time = $val[2] || $val[3] || $val[4] || $val[5] || $val[6];
                return undef unless $time;
                my $secs = Image::ExifTool::GetUnixTime($time, 1);
                return undef unless $secs;
                my @info = Image::ExifTool::Geolocation::GetEntry($$loc[0]);
                $self->Options(TimeZone => $info[5]);
                my $localTime = Image::ExifTool::ConvertUnixTime($secs, 1);
                $self->Options(TimeZone => undef);
                return $localTime;
            },
        },
    },
);

1; #end

